Created
August 17, 2018 12:44
-
-
Save emiaj/e8eeb3546de8790c76bf829669bc281d to your computer and use it in GitHub Desktop.
Curry
This file contains 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
declare type Curry<P, V> = | |
P extends [infer A, infer B, infer C, infer D] ? (a: A) => Curry<[B, C, D], V> : | |
P extends [infer A, infer B, infer C] ? (a: A) => Curry<[B, C], V> : | |
P extends [infer A, infer B] ? (a: A) => Curry<[B], V> : | |
P extends [infer A] ? (a: A) => V : | |
() => V; // could be unknow, but this allows to safely pass parameterless functions | |
declare function curry<T extends any[], R>(fn: (...args: T) => R): Curry<T, R>; | |
const add = curry((a: number, b: number, c: number) => a + b + c); | |
add(1)(2)(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment