Function: curry()
Returns a curried version of the given function f
. The returned
function behaves just like f
, except that, if is passed fewer arguments
than f
requires, it does nothing but return a new curried function that
takes the remaining arguments. f
is called once all arguments have been
supplied.
Example
import {curry} from "@longlast/curry";
const multiply = curry((a: number, b: number) => a * b);
// `multiply` can be called normally, with both arguments...
multiply(3, 4); // => 12
// ...or it can be partially applied:
[1, 2, 3].map(multiply(2)); // => [2, 4, 6]
Limitations
- The types for
curry
only support functions of up to five arguments. - Functions with rest parameters (e.g.
...args
) or optional parameters are not supported. Thearguments
object is not supported either. You should only curry functions that have a fixed number of named parameters. - Functions with type parameters are not supported.
Call Signature
curry<
A
,B
,Return
>(f
: (a
:A
,b
:B
) =>Return
):Curried2
<A
,B
,Return
>
Defined in: pkg/curry/src/index.ts:17
Type Parameters
Type Parameter | Description |
---|---|
A |
the type of f 's first argument |
B |
the type of f 's second argument |
Return |
the return type of f |
Parameters
Parameter | Type | Description |
---|---|---|
f |
(a : A , b : B ) => Return |
the function to curry |
Returns
Curried2
<A
, B
, Return
>
Call Signature
curry<
A
,B
,C
,Return
>(f
: (a
:A
,b
:B
,c
:C
) =>Return
):Curried3
<A
,B
,C
,Return
>
Defined in: pkg/curry/src/index.ts:21
Type Parameters
Type Parameter | Description |
---|---|
A |
the type of f 's first argument |
B |
the type of f 's second argument |
C |
the type of f 's third argument |
Return |
the return type of f |
Parameters
Parameter | Type | Description |
---|---|---|
f |
(a : A , b : B , c : C ) => Return |
the function to curry |
Returns
Curried3
<A
, B
, C
, Return
>
Call Signature
curry<
A
,B
,C
,D
,Return
>(f
: (a
:A
,b
:B
,c
:C
,d
:D
) =>Return
):Curried4
<A
,B
,C
,D
,Return
>
Defined in: pkg/curry/src/index.ts:25
Type Parameters
Type Parameter | Description |
---|---|
A |
the type of f 's first argument |
B |
the type of f 's second argument |
C |
the type of f 's third argument |
D |
the type of f 's fourth argument |
Return |
the return type of f |
Parameters
Parameter | Type | Description |
---|---|---|
f |
(a : A , b : B , c : C , d : D ) => Return |
the function to curry |
Returns
Curried4
<A
, B
, C
, D
, Return
>
Call Signature
curry<
A
,B
,C
,D
,E
,Return
>(f
: (a
:A
,b
:B
,c
:C
,d
:D
,e
:E
) =>Return
):Curried5
<A
,B
,C
,D
,E
,Return
>
Defined in: pkg/curry/src/index.ts:29
Type Parameters
Type Parameter | Description |
---|---|
A |
the type of f 's first argument |
B |
the type of f 's second argument |
C |
the type of f 's third argument |
D |
the type of f 's fourth argument |
E |
the type of f 's fifth argument |
Return |
the return type of f |
Parameters
Parameter | Type | Description |
---|---|---|
f |
(a : A , b : B , c : C , d : D , e : E ) => Return |
the function to curry |
Returns
Curried5
<A
, B
, C
, D
, E
, Return
>