Skip to content

Instantly share code, notes, and snippets.

@freddi301
Created March 5, 2019 16:51
Show Gist options
  • Save freddi301/4be0ce82128b753f40a0e061da42610c to your computer and use it in GitHub Desktop.
Save freddi301/4be0ce82128b753f40a0e061da42610c to your computer and use it in GitHub Desktop.
TypeScript function composition
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