Created
June 22, 2020 07:34
-
-
Save ddprrt/9aafa1eb8738a3250e09e2b4c2c54095 to your computer and use it in GitHub Desktop.
Currying with variadic tuple types
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
function curry<T extends unknown[], U extends unknown[], V>( | |
f: (...ts: [...T, ...U]) => V, | |
...a: T | |
): (...b: U) => V { | |
return (...b) => f(...a, ...b); | |
} | |
const input = (a: number, b: string, c: boolean, d: symbol) => | |
[a, b, c, d] as const; | |
curry(input, 1, "123", true, Symbol())(); | |
curry(input, 1, "123", true)(Symbol()); | |
curry(input, 1, "123")(true, Symbol()); | |
curry(input, 1)("2", true, Symbol()) | |
curry(input)(1, "123", true, Symbol()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment