How to use the curry function from lodash

Find comprehensive JavaScript lodash.curry code examples handpicked from public code repositorys.

65
66
67
68
69
70
71
72
73
74
 * given package
 * @param {Package} pkg
 * @param {string} pkgPath
 * @returns {Array<string>}
 */
const findEntryPoints = _.curry((pkg, pkgPath) => {
  try {
    let paths = [];

    if (pkg.main) {
fork icon305
star icon154
watch icon43

+ 17 other calls in file

6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
* @param {Function} func The function to curry.
* @param {number} [arity=func.length] The arity of `func`.
* @returns {Function} Returns the new curried function.
* @example
*
* var curried = _.curry(function(a, b, c) {
*   console.log(a + b + c);
* });
*
* curried(1)(2)(3);
fork icon73
star icon711
watch icon29

67
68
69
70
71
72
73
74
75
76
module.exports.conjoin             = _.conjoin;
module.exports.cons                = _.cons;
module.exports.constant            = _.constant;
module.exports.countBy             = _.countBy;
module.exports.create              = _.create;
module.exports.curry               = _.curry;
module.exports.curry2              = _.curry2;
module.exports.curry3              = _.curry3;
module.exports.curryRight          = _.curryRight;
module.exports.curryRight2         = _.curryRight2;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

26
27
28
29
30
31
32
33
34
35
36
const biOp = function(a, b, c) {
	return a(b + c);
};


// use auto-currying for functions with fixed arity of func.length
const biOpCurried = _.curry(biOp);
const plus = biOpCurried(sum);
const addFivePFive = plus(5.5);
	
addFivePFive(4.5);
fork icon1
star icon10
watch icon0

56
57
58
59
60
61
62
63
64
65
},
{
  name: 'curry.partial',
  benchmarks: () => {
    const iirisAdd = I.curry3((a, b, c) => a + b + c)
    const lodashAdd = _.curry((a, b, c) => a + b + c)
    const ramdaAdd = R.curry((a, b, c) => a + b + c)
    const nativeAdd = (a) => (b) => (c) => a + b + c

    return {
fork icon1
star icon31
watch icon0

+ 5 other calls in file

305
306
307
308
309
310
311
312
313
314
315
316
317
bind(); // => 'hello'


const bindKey = _.bindKey(console, 'log', 'hello');
bindKey(); // => 'hello'


const curry = _.curry((a, b, c) => a + b + c);
console.log(curry(1)(2)(3)); // => 6


const curryRight = _.curryRight((a, b, c) => a + b + c);
console.log(curryRight(3)(2)(1)); // => 6
fork icon0
star icon4
watch icon0

+ 15 other calls in file

48
49
50
51
52
53
54
55
56
57
58
59
logger.info('умножаем число 21 на 2 через partial  = ' + double(21))
logger.info('делим на 2 число 20 через partialRight = ' + half(20))
logger.info('делим число 20 на 2 через partial = ' + half2(20))


//curry ====================== //функция возвращает новую функцию которая ждет остальные параметры
const curriedDivide = _.curry(divide)


logger.info('делим число 20 на 2 через curry1 = ' + curriedDivide(10, 2))
logger.info('делим число 20 на 2 через curry2 = ' + curriedDivide(10)(2))

fork icon0
star icon1
watch icon0

53
54
55
56
57
58
59
60
61
62
63
64
65
66


var valueCounter = _.curry(countCards)(0);
//create a function that takes index as a parameter
  //at 0 it calculates for our card strength
  //at 1 it calculates for our suits
var countSuits = _.curry(countCards)(1);






function twoPair(hand) {
fork icon0
star icon0
watch icon0

+ 9 other calls in file

611
612
613
614
615
616
617
618
619
620
621
622
// );


// const someFunc = (a, b, c) => {
//   return [a, b, c];
// };
// const curriedFunc = lodash.curry(someFunc);
// console.log(curriedFunc(1)(2)(3));
// console.log(curriedFunc(1)(5)(3));


// //castArray
fork icon0
star icon0
watch icon0

+ 11 other calls in file

95
96
97
98
99
100
101
102
103
104
  const thisArg = {
    logger,
    logResponseDataUrl: config?.logResponseDataUrl ?? [],
    requestBodyAdapter: config?.requestBodyAdapter ?? ((url, body) => body)
  };
  return _.curry(logResponse.bind(thisArg), 2)(_, isError);
}


module.exports = buildResponseLogger;
fork icon0
star icon0
watch icon0

-3
fork icon0
star icon0
watch icon0

+ 3 other calls in file

71
72
73
74
75
76
77
78
79
80
81


//_.curry(func,[arity=func.length])
var abc = function (a, b, c) {
    return [a, b, c];
}
var curried = _.curry(abc);
var curried1 = curried(1)(2)(3);
console.log('curried1--->', curried1);
//curried1---> [ 1, 2, 3 ]
var curried2 = curried(1, 2)(3);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

13
14
15
16
17
18
19
20
21
22
23
24
25
  }


  return map[operator]
}


const matchCursorResult = _.curry((decodedCursor, result) => {
  const normalizeValue = prop => prop instanceof Date ? prop.toISOString() : prop


  return Object.keys(decodedCursor).every(k => {
    return normalizeValue(result[k]) === normalizeValue(decodedCursor[k])
fork icon0
star icon0
watch icon0

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)