Created
March 5, 2019 16:51
-
-
Save freddi301/4be0ce82128b753f40a0e061da42610c to your computer and use it in GitHub Desktop.
TypeScript function composition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pipe<A, B>(f: (a: A) => B) { | |
return { | |
end: f, | |
pipe<C>(g: (b: B) => C) { | |
return pipe((a: A) => g(f(a))); | |
} | |
}; | |
} | |
function compose<A, B>(f: (a: A) => B) { | |
return { | |
end: f, | |
pipe<C>(g: (c: C) => A) { | |
return pipe((c: C) => f(g(c))); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment