-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
export default curry; | ||
|
||
// TODO: get more specific with permssible param types for returned function | ||
declare function curry( | ||
fn: Function, | ||
arity?: number, | ||
) : Function; | ||
type MakeTuple<LEN extends number, T extends any = any, C extends T[] = []> = C['length'] extends LEN ? C : MakeTuple<LEN, T, [T, ...C]> | ||
type CurryOverload<F extends (...args: any[]) => any, N extends unknown[], P extends unknown[]> = | ||
N extends [infer L, ...infer R] | ||
? ((...args: [...P, L]) => CurryInternal<F, R>) & CurryOverload<F, R, [...P, L]> | ||
: () => CurryInternal<F, P> | ||
type CurryInternal<F extends (...args: any[]) => any, N extends unknown[]> = | ||
0 extends N['length'] ? ReturnType<F> : CurryOverload<F, N, []> | ||
type Curry<F extends (...args: any[]) => any, LEN extends number | undefined = undefined, I extends any = any> = | ||
0 extends (LEN extends undefined ? Parameters<F>['length'] : LEN) | ||
? () => ReturnType<F> | ||
: CurryInternal<F, LEN extends undefined ? Parameters<F> : MakeTuple<LEN extends undefined ? 0 : LEN, I>> | ||
|
||
declare function curry<F extends (...args: any[]) => any, L extends number>( | ||
fn: F, | ||
arity?: L | undefined, | ||
) : Curry<F, number extends L ? undefined : L, Parameters<F>[number]>; |
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