All idempotents splits in set theory context So I wanted to show that in the category $\mathbf{SET}$, all idempotent splits.
Fix an idempotent $f$, I wish to find 2 arrows $g,h$ such that $f=hg$ and $gh = 1$.
I'm having some trouble "decomposing" such an $f$. However what I did notice is that if I can find an injective $h$ and a surjective $g$, then $gh = 1$ is fulfilled automatically since 
$f^2 = f \rightarrow hghg = hg 
\\ \rightarrow ghg = g\ \text{ (Since h is injective hence monic in Set)} \\ \rightarrow gh = 1\ (\ \text{Since g is surjective, hence an epi in Set})$
So how can I decompose an idempotent  $f$ into an injective and surjective component ? 
If I'm on the wrong track, any hints/insights is deeply appreciated.
Cheers and thanks
 A: If you've done any linear algebra, then picturing projections in your mind should help. 
But the point is valid of course in sets as well, linear algebra is just a way to picture it : $f^2=f$ means $f$ is a "projection onto its image". Therefore if $f:X\to X$, $f^2=f$ then you can put $Y=f(X)$, then $Y$ is a subset of $X$ so the inclusion $Y\to X$ is injective, and the corestriction of $f$ to its image, $g:X\to Y$ is clearly surjective. Moreover it's easy to check that $f=(inclusion)\circ g$
Note that checking $gh = id$ can be done abstractly as you did, or it can be done more directly here : if $y\in Y$, then $y=f(x)$ for some $x$ so $gh(y) = gf(x)= f^2(x) = f(x) = y$
A: In the category of sets every morphism $f$ factors as $f=gh$, where $h$ is epic (surjective) and $g$ is monic (injective).
What are $g$ and $h$? Consider a map $f\colon X\to Y$ (this can be done generally) and the equivalence relation $\sim_f$ on $X$ defined by $a\sim_f b$ if and only if $f(a)=f(b)$.
Let $X/{\sim_f}$ be the quotient set and $h\colon X\to X/{\sim_f}$ be the obvious map that sends $x\in X$ to the equivalence class it belongs to. Now prove that there exists a unique map $g\colon X/{\sim_f}\to Y$ such that $gh(x)=f(x)$, for every $x\in X$.
In the case $f\colon X\to X$ is idempotent, from $f^2=f$ we get
$$
ghgh=gh
$$
Since $g$ is monic, it is left cancellable; since $h$ is epic, it is right cancellable. Therefore $hg=1$.
