Created
August 27, 2019 21:49
-
-
Save Willmo36/3ea040a89206641e8a61212d5daa57e7 to your computer and use it in GitHub Desktop.
TypeScript flip n uncurry
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 flip<Args1 extends any[], Args2 extends any[], R>( | |
fn: (...args1: Args1) => (...args2: Args2) => R | |
) { | |
return (...args2: Args2) => (...args1: Args1) => fn(...args1)(...args2); | |
} | |
function uncurry<A, Args2 extends any[], R>( | |
fn: (arg: A) => (...args2: Args2) => R | |
) { | |
return (arg: A, ...args2: Args2) => fn(arg)(...args2); | |
} | |
const foo = <A,B>(a: A, a2: A) => (b: B): string => "hello" | |
const bar = flip(foo); | |
const baz = uncurry(bar); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment