How to use the over function from lodash

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

lodash.over creates a function that invokes an array of functions and returns their results as an array.

284
285
286
287
288
289
290
291
292
293
module.exports.omit                = _.omit;
module.exports.omitBy              = _.omitBy;
module.exports.omitWhen            = _.omitWhen;
module.exports.once                = _.once;
module.exports.orderBy             = _.orderBy;
module.exports.over                = _.over;
module.exports.overArgs            = _.overArgs;
module.exports.overEvery           = _.overEvery;
module.exports.overSome            = _.overSome;
module.exports.pad                 = _.pad;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

932
933
934
935
936
937
938
939
940
941
942
943
944
console.log(noop); // => undefined


const nthArg = _.nthArg(1);
console.log(nthArg('a', 'b', 'c', 'd')); // => 'b'


const over = _.over([Math.max, Math.min]);
console.log(over(1, 2, 3, 4)); // => [4, 1]


const overEvery = _.overEvery([Boolean, isFinite]);
console.log(overEvery('1')); // => true
fork icon0
star icon4
watch icon0

+ 15 other calls in file

How does lodash.over work?

lodash.over is a function that takes multiple functions as arguments and returns a new function that invokes each of the original functions with the same arguments, returning an array of their results.

For example, _.over(func1, func2)(value) is equivalent to [func1(value), func2(value)].

Ai Example

1
2
3
const getMax = _.over(Math.max, (a, b) => b);
console.log(getMax(1, 2)); // 2
console.log(getMax(2, 1)); // 1

In this example, getMax is a new function created by calling _.over with Math.max and an arrow function that returns the second argument (b). When getMax is called with two numbers, it first calls Math.max with the same arguments, then calls the arrow function with the same arguments and returns its result. In effect, getMax returns the maximum of two numbers, but if the two numbers are equal, it returns the second one.

Other functions in lodash

Sorted by popularity

function icon

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