Define functions in a tikzcd diagram

As long as you add an ampersand replacement you can use these arrays.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}[column sep=8em,ampersand replacement=\&]
        \& N  \arrow[twoheadrightarrow,d,"\pi"]\\
        R^{\bigoplus\mathcal{I}} \arrow[r,"{\begin{array}{rcl}
 \gamma \colon R^{\bigoplus\mathcal{I}} & \longrightarrow & M\\
 e_{i} & \longmapsto & \gamma(e_{i})
\end{array}}" swap] 
\arrow[ur,"{\begin{array}{rcl}
\beta \colon R^{\bigoplus\mathcal{I}} & \longrightarrow & N\\
 e_{i} & \longmapsto & g_{i}
\end{array}}" sloped] \& M \arrow[u,twoheadrightarrow,bend right=80,"{\begin{array}{rcl}
\pi^{-1} \colon M & \longrightarrow & N\\
 \gamma(e_{i}) & \longmapsto & g_{i}
\end{array}}" swap]
    \end{tikzcd}
\end{document}

enter image description here


Define a macro for the complicated thing:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}

\newcommand{\funcdef}[5]{%
  \mbox{\scriptsize$
    \begin{aligned} #1\colon #2 & \longrightarrow #3 \\[-1ex] #4 &\longmapsto #5 \end{aligned}
  $}%
}


\begin{document}

\begin{tikzcd}[column sep=8em]
& N \arrow[twoheadrightarrow,d,"\pi"]\\
R^{\bigoplus\mathcal{I}}
  \arrow[r,"\funcdef{\gamma}{R^{\bigoplus\mathcal{I}}}{M}{e_{i}}{\gamma(e_{i})}"']
  \arrow[ur,"\funcdef{\beta}{R^{\bigoplus\mathcal{I}}}{N}{e_{i}}{g_{i}}" sloped] &
M \arrow[u,twoheadrightarrow,bend right=80,"\funcdef{\pi^{-1}}{M}{N}{\gamma(e_{i})}{g_{i}}"']
\end{tikzcd}

\end{document}

enter image description here


For fun, a solution with the psmatrix environment, from pstricks:

\documentclass{article}
\usepackage{amsmath}
 \usepackage{pst-node}

\begin{document}
%
 \[
 \everypsbox{\scriptstyle}
 \psset{arrows=->, arrowinset=0.15, linewidth=0.4pt, nodesep=3pt, labelsep=2pt, rowsep=1.2cm, colsep=1.5cm, shortput=nab}
 \begin{psmatrix}
%%%nodes
 & [name=N] N \\%
R^{ \oplus \mathcal{I}}\pnode{R} & [name=M] M
     \end{psmatrix}
%%% arrows
 \ncline{2,1}{1,2}\naput[npos=0.45,labelsep =0pt]{\beta }
 \ncline{2,1}{2,2}^{\gamma }
 \ncline{1,2}{2,2}_{\pi }
%%%%
 \psset{arrows=|->,offset =2.5ex}
 \ncline{2,1}{1,2}
\uput{4ex}[125]{45}(R){e_i}
\uput{2ex}[140]{45}(N){g_i}
%%%
 \ncline[offset=-2ex]{2,1}{2,2}
\uput{1ex}[-110]{0}(R){e_i}
\uput{1ex}[-60]{0}(M){\gamma (e_i)}
%%%
 \ncline[linestyle=dashed, arrows=<-|]{1,2}{2,2}\naput[npos=0.43]{\pi^{-1}}
\uput{2ex}[r]{0}(N){g_i}
 \]

\end{document} 

enter image description here