Skip to content

Instantly share code, notes, and snippets.

@ddprrt
Created June 22, 2020 07:34
Show Gist options
  • Save ddprrt/9aafa1eb8738a3250e09e2b4c2c54095 to your computer and use it in GitHub Desktop.
Save ddprrt/9aafa1eb8738a3250e09e2b4c2c54095 to your computer and use it in GitHub Desktop.
Currying with variadic tuple types
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