Consolidate over modules.

This commit is contained in:
John-David Dalton
2017-01-11 12:11:56 -08:00
parent 36927bff8b
commit 3b4cbc70e7
5 changed files with 27 additions and 36 deletions

View File

@@ -1,19 +0,0 @@
import apply from './.internal/apply.js';
/**
* Creates a function like `over`.
*
* @private
* @param {Function} arrayFunc The function to iterate over iteratees.
* @returns {Function} Returns the new over function.
*/
function createOver(arrayFunc) {
return (...iteratees) => {
return function(...args) {
const thisArg = this;
return arrayFunc(iteratees, iteratee => apply(iteratee, thisArg, args));
};
};
}
export default createOver;

11
over.js
View File

@@ -1,5 +1,5 @@
import apply from './.internal/apply.js';
import arrayMap from './.internal/arrayMap.js';
import createOver from './.internal/createOver.js';
/**
* Creates a function that invokes `iteratees` with the arguments it receives
@@ -7,7 +7,7 @@ import createOver from './.internal/createOver.js';
*
* @since 4.0.0
* @category Util
* @param {...(Function|Function[])} [iteratees=[identity]]
* @param {Function[]} [iteratees=[identity]]
* The iteratees to invoke.
* @returns {Function} Returns the new function.
* @example
@@ -17,6 +17,11 @@ import createOver from './.internal/createOver.js';
* func(1, 2, 3, 4);
* // => [4, 1]
*/
const over = createOver(arrayMap);
function over(iteratees) {
return function(...args) {
const thisArg = this;
return arrayMap(iteratees, iteratee => apply(iteratee, thisArg, args));
};
}
export default over;

View File

@@ -1,8 +1,4 @@
import apply from './.internal/apply.js';
import baseFlatten from './.internal/baseFlatten.js';
/* Built-in method references for those with the same name as other `lodash` methods. */
const nativeMin = Math.min;
/**
* Creates a function that invokes `func` with its arguments transformed.
@@ -10,7 +6,7 @@ const nativeMin = Math.min;
* @since 4.0.0
* @category Function
* @param {Function} func The function to wrap.
* @param {...(Function|Function[])} [transforms=[identity]]
* @param {Function[]} [transforms=[identity]]
* The argument transforms.
* @returns {Function} Returns the new function.
* @example
@@ -31,12 +27,11 @@ const nativeMin = Math.min;
* func(10, 5);
* // => [100, 10]
*/
function overArgs(func, ...transforms) {
function overArgs(func, transforms) {
const funcsLength = transforms.length;
return function(...args) {
let index = -1;
const length = nativeMin(args.length, funcsLength);
const length = Math.min(args.length, funcsLength);
while (++index < length) {
args[index] = transforms[index].call(this, args[index]);
}

View File

@@ -1,5 +1,5 @@
import apply from './.internal/apply.js';
import arrayEvery from './.internal/arrayEvery.js';
import createOver from './.internal/createOver.js';
/**
* Creates a function that checks if **all** of the `predicates` return
@@ -7,7 +7,7 @@ import createOver from './.internal/createOver.js';
*
* @since 4.0.0
* @category Util
* @param {...(Function|Function[])} [predicates=[identity]]
* @param {Function[]} [predicates=[identity]]
* The predicates to check.
* @returns {Function} Returns the new function.
* @example
@@ -23,6 +23,11 @@ import createOver from './.internal/createOver.js';
* func(NaN);
* // => false
*/
const overEvery = createOver(arrayEvery);
function overEvery(iteratees) {
return function(...args) {
const thisArg = this;
return arrayEvery(iteratees, iteratee => apply(iteratee, thisArg, args));
};
}
export default overEvery;

View File

@@ -1,5 +1,5 @@
import apply from './.internal/apply.js';
import arraySome from './.internal/arraySome.js';
import createOver from './.internal/createOver.js';
/**
* Creates a function that checks if **any** of the `predicates` return
@@ -7,7 +7,7 @@ import createOver from './.internal/createOver.js';
*
* @since 4.0.0
* @category Util
* @param {...(Function|Function[])} [predicates=[identity]]
* @param {Function[]} [predicates=[identity]]
* The predicates to check.
* @returns {Function} Returns the new function.
* @example
@@ -23,6 +23,11 @@ import createOver from './.internal/createOver.js';
* func(NaN);
* // => false
*/
const overSome = createOver(arraySome);
function overSome(iteratees) {
return function(...args) {
const thisArg = this;
return arraySome(iteratees, iteratee => apply(iteratee, thisArg, args));
};
}
export default overSome;