8000 Consolidate `over` modules. · lodash/lodash@3b4cbc7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b4cbc7

Browse files
committed
Consolidate over modules.
1 parent 36927bf commit 3b4cbc7

File tree

5 files changed

+27
-36
lines changed

5 files changed

+27
-36
lines changed

.internal/createOver.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

over.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import apply from './.internal/apply.js';
12
import arrayMap from './.internal/arrayMap.js';
2-
import createOver from './.internal/createOver.js';
33

44
/**
55
* Creates a function that invokes `iteratees` with the arguments it receives
66
* and returns their results.
77
*
88
* @since 4.0.0
99
* @category Util
10-
* @param {...(Function|Function[])} [iteratees=[identity]]
10+
* @param {Function[]} [iteratees=[identity]]
1111
* The iteratees to invoke.
1212
* @returns {Function} Returns the new function.
1313
* @example
@@ -17,6 +17,11 @@ import createOver from './.internal/createOver.js';
1717
* func(1, 2, 3, 4);
1818
* // => [4, 1]
1919
*/
20-
const over = createOver(arrayMap);
20+
function over(iteratees) {
21+
return function(...args) {
22+
const thisArg = this;
23+
return arrayMap(iteratees, iteratee => apply(iteratee, thisArg, args));
24+
};
25+
}
2126

2227
export default over;

overArgs.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import apply from './.internal/apply.js';
2-
import baseFlatten from './.internal/baseFlatten.js';
3-
4-
/* Built-in method references for those with the same name as other `lodash` methods. */
5-
const nativeMin = Math.min;
62

73
/**
84
* Creates a function that invokes `func` with its arguments transformed.
95
*
106
* @since 4.0.0
117
* @category Function
128
* @param {Function} func The function to wrap.
13-
* @param {...(Function|Function[])} [transforms=[identity]]
9+
* @param {Function[]} [transforms=[identity]]
1410
* The argument transforms.
1511
* @returns {Function} Returns the new function.
1612
* @example
@@ -31,12 +27,11 @@ const nativeMin = Math.min;
3127
* func(10, 5);
3228
* // => [100, 10]
3329
*/
34-
function overArgs(func, ...transforms) {
30+
function overArgs(func, transforms) {
3531
const funcsLength = transforms.length;
3632
return function(...args) {
3733
let index = -1;
38-
const length = nativeMin(args.length, funcsLength);
39-
34+
const length = Math.min(args.length, funcsLength);
4035
while (++index < length) {
4136
args[index] = transforms[index].call(this, args[index]);
4237
}

overEvery.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import apply from './.internal/apply.js';
12
import arrayEvery from './.internal/arrayEvery.js';
2-
import createOver from './.internal/createOver.js';
33

44
/**
55
* Creates a function that checks if **all** of the `predicates` return
66
* truthy when invoked with the arguments it receives.
77
*
88
* @since 4.0.0
99
* @category Util
10-
* @param {...(Function|Function[])} [predicates=[identity]]
10+
* @param {Function[]} [predicates=[identity]]
1111
* The predicates to check.
1212
* @returns {Function} Returns the new function.
1313
* @example
@@ -23,6 +23,11 @@ import createOver from './.internal/createOver.js';
2323
* func(NaN);
2424
* // => false
2525
*/
26-
const overEvery = createOver(arrayEvery);
26+
function overEvery(iteratees) {
27+
return function(...args) {
28+
const thisArg = this;
29+
return arrayEvery(iteratees, iteratee => apply(iteratee, thisArg, args));
30+
};
31+
}
2732

2833
export default overEvery;

overSome.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import apply from './.internal/apply.js';
12
import arraySome from './.internal/arraySome.js';
2-
import createOver from './.internal/createOver.js';
33

44
/**
55
* Creates a function that checks if **any** of the `predicates` return
66
* truthy when invoked with the arguments it receives.
77
*
88
* @since 4.0.0
99
* @category Util
10-
* @param {...(Function|Function[])} [predicates=[identity]]
10+
* @param {Function[]} [predicates=[identity]]
1111
* The predicates to check.
1212
* @returns {Function} Returns the new function.
1313
* @example
@@ -23,6 +23,11 @@ import createOver from './.internal/createOver.js';
2323
* func(NaN);
2424
* // => false
2525
*/
26-
const overSome = createOver(arraySome);
26+
function overSome(iteratees) {
27+
return function(...args) {
28+
const thisArg = this;
29+
return arraySome(iteratees, iteratee => apply(iteratee, thisArg, args));
30+
};
31+
}
2732

2833
export default overSome;

0 commit comments

Comments
 (0)
0