Creates a function that accepts arguments of funcand either invokes funcreturning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining func arguments, and so on. The arity of func may be specified if func.length is not sufficient.

The _.curry.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder for provided arguments.

Concrètement :

JavaScript

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

var abc=function(a,b,c){

return[a,b,c];

};

varcurried=_.curry(abc);

curried(1)(2)(3);

// => [1, 2, 3]

curried(1,2)(3);

// => [1, 2, 3]

curried(1,2,3);

// => [1, 2, 3]

// Curried with placeholders.

curried(1)(_,3)(2);

// => [1, 2, 3]

Concrètement sur notre exemple, cela donne :

JavaScript

1

2

3

varnewcurried=_.curry(find);

varresult=newcurried(users)('fred');

console.log('---> Age of fred with _.curry? '+JSON.stringify(result));