Skip to content

Instantly share code, notes, and snippets.

@Willmo36
Created August 27, 2019 21:49
Show Gist options
  • Save Willmo36/3ea040a89206641e8a61212d5daa57e7 to your computer and use it in GitHub Desktop.
Save Willmo36/3ea040a89206641e8a61212d5daa57e7 to your computer and use it in GitHub Desktop.
TypeScript flip n uncurry
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