Given a value returns a function that will always return that value.
Given a list of arguments and a function, applies the function with
the given arguments.
Right-to-left function composition.
Given a function it returns a curried version of that function.
See the code
export const curry: CurryFn = function curry(fn: any) {
switch (fn.length) {
case 0:
return fn
case 1:
return fn
case 2:
return curry2(fn as Curry2<any, any, any>)
case 3:
return curry3(fn as Curry3<any, any, any, any>)
case 4:
return curry4(fn as Curry4<any, any, any, any, any>)
case 5:
return curry5(fn as Curry5<any, any, any, any, any, any>)
default:
return curryN(fn.length, fn)
}
}
export type CurryFn = {
<A>(f: () => A): () => A
<A, B>(f: Arity1<A, B>): Arity1<A, B>
<A, B, C>(f: Arity2<A, B, C>): Curry2<A, B, C>
<A, B, C, D>(f: Arity3<A, B, C, D>): Curry3<A, B, C, D>
<A, B, C, D, E>(f: Arity4<A, B, C, D, E>): Curry4<A, B, C, D, E>
<A, B, C, D, E, F>(f: Arity5<A, B, C, D, E, F>): Curry5<A, B, C, D, E, F>
<A, B, C, D, E, F, G>(f: Arity6<A, B, C, D, E, F, G>): Curry6<A, B, C, D, E, F, G>
<A, B, C, D, E, F, G, H>(f: Arity7<A, B, C, D, E, F, G, H>): Curry7<A, B, C, D, E, F, G, H>
<A, B, C, D, E, F, G, H, I>(f: Arity8<A, B, C, D, E, F, G, H, I>): Curry8<
A,
B,
C,
D,
E,
F,
G,
H,
I
>
<A, B, C, D, E, F, G, H, I, J>(f: Arity9<A, B, C, D, E, F, G, H, I, J>): Curry9<
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
>
<A, B, C, D, E, F, G, H, I, J, K>(f: Arity10<A, B, C, D, E, F, G, H, I, J, K>): Curry10<
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
>
}
Flips the first 2 arguments of a function.
Memoizes a function.
Left-to-right function composition.