(The following code uses math examples you posted initially.)
Depending on the type of alignment you want, one of the following two solutions may work for you.

\documentclass{article}
\usepackage{array}
\begin{document}
If you want flush-left alignment:
\[
f\colon \begin{array}{>{\displaystyle}l}
X \rightarrow Y \\
x\mapsto f(x)=\frac{x-1}{2}
\end{array}
\]
\bigskip
If the arrows have to be aligned vertically:
\[
f\colon \begin{array}{>{\displaystyle}r @{} >{{}}c<{{}} @{} >{\displaystyle}l}
X &\rightarrow& Y \\
x &\mapsto& f(x)=\frac{x-1}{2}
\end{array}
\]
\end{document}
Addendum: To align the first row of the array
with f\colon
, provide the [t]
placement option after \begin{array}

\documentclass{article}
\usepackage{array}
\begin{document}
If \verb+f\colon+ should be on the same line as \verb+X\to Y+:
\[
\setlength\arraycolsep{0pt}
f\colon \begin{array}[t]{ >{\displaystyle}r >{{}}c<{{}} >{\displaystyle}l }
X &\to& Y \\
x &\mapsto& f(x)=\frac{x-1}{2}
\end{array}
\]
\end{document}
$$
in LaTeX.