Skip to content

Instantly share code, notes, and snippets.

@jakelazaroff
Created July 19, 2018 18:01
Show Gist options
  • Save jakelazaroff/70861839170e2c427517bc93cd2363b7 to your computer and use it in GitHub Desktop.
Save jakelazaroff/70861839170e2c427517bc93cd2363b7 to your computer and use it in GitHub Desktop.
type Fn<A, B> = (a: A) => B;
function compose<A, B>(f1: Fn<A, B>): Fn<A, B>;
function compose<A, B, C>(f1: Fn<B, C>, fn2: Fn<A, B>): Fn<A, C>;
function compose<A, B, C, D>(
fn1: Fn<C, D>,
f2: Fn<B, C>,
fn3: Fn<A, B>
): Fn<A, D>;
function compose<A, B, C, D, E>(
fn1: Fn<D, E>,
fn2: Fn<C, D>,
f2: Fn<B, C>,
fn3: Fn<A, B>
): Fn<A, E>;
function compose<A>(...fns: any[]) {
return (a: A) =>
fns.reverse().reduce((result, current) => current(result), a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment