Assume that $X$ and $Y$ are random varaibles. The theory of conditional expectation says that the function f that minimizes $E[(Y-f(X))^2]$ is $f(x)=E[Y|X=x]$.
My book says that the function that minimizes $E[|Y-f(X)|]$ is $f(x)=\text{median}(Y|X=x)$. But how do we show this last result? Does it follow from the theory of conditional expectation?