Last active
August 14, 2025 20:47
-
-
Save moimikey/700e61bd52f3f4ff684e568504a9c6f3 to your computer and use it in GitHub Desktop.
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
| export type Curry<F extends (...args: readonly unknown[]) => unknown> = | |
| Parameters<F> extends readonly [infer First, ...infer Rest] | |
| ? (arg: First) => Rest extends readonly [] | |
| ? ReturnType<F> | |
| : Curry<(...args: Rest) => ReturnType<F>> | |
| : ReturnType<F>; | |
| export function curry<F extends (...args: readonly unknown[]) => unknown>(fn: F): Curry<F> { | |
| function curried(...providedArgs: readonly unknown[]): unknown { | |
| if (providedArgs.length >= fn.length) { | |
| return fn(...(providedArgs.slice(0, fn.length) as Parameters<F>)); | |
| } | |
| return (...newArgs: readonly unknown[]) => { | |
| return curried(...providedArgs, ...newArgs); | |
| }; | |
| } | |
| return curried as Curry<F>; | |
| } |
Author
moimikey
commented
Aug 14, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment