Created
July 19, 2018 18:01
-
-
Save jakelazaroff/70861839170e2c427517bc93cd2363b7 to your computer and use it in GitHub Desktop.
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
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