Remove unary helpers.

This commit is contained in:
John-David Dalton
2017-01-09 16:20:00 -08:00
parent 59124c4cfe
commit efcf51c7bf
15 changed files with 27 additions and 64 deletions

View File

@@ -2,7 +2,6 @@ import SetCache from './_SetCache.js';
import arrayIncludes from './_arrayIncludes.js'; import arrayIncludes from './_arrayIncludes.js';
import arrayIncludesWith from './_arrayIncludesWith.js'; import arrayIncludesWith from './_arrayIncludesWith.js';
import arrayMap from './_arrayMap.js'; import arrayMap from './_arrayMap.js';
import baseUnary from './_baseUnary.js';
import cacheHas from './_cacheHas.js'; import cacheHas from './_cacheHas.js';
/** Used as the size to enable large array optimizations. */ /** Used as the size to enable large array optimizations. */
@@ -31,7 +30,7 @@ function baseDifference(array, values, iteratee, comparator) {
return result; return result;
} }
if (iteratee) { if (iteratee) {
values = arrayMap(values, baseUnary(iteratee)); values = arrayMap(values, value => iteratee(value));
} }
if (comparator) { if (comparator) {
includes = arrayIncludesWith; includes = arrayIncludesWith;

View File

@@ -2,7 +2,6 @@ import SetCache from './_SetCache.js';
import arrayIncludes from './_arrayIncludes.js'; import arrayIncludes from './_arrayIncludes.js';
import arrayIncludesWith from './_arrayIncludesWith.js'; import arrayIncludesWith from './_arrayIncludesWith.js';
import arrayMap from './_arrayMap.js'; import arrayMap from './_arrayMap.js';
import baseUnary from './_baseUnary.js';
import cacheHas from './_cacheHas.js'; import cacheHas from './_cacheHas.js';
/* Built-in method references for those with the same name as other `lodash` methods. */ /* Built-in method references for those with the same name as other `lodash` methods. */
@@ -32,7 +31,7 @@ function baseIntersection(arrays, iteratee, comparator) {
while (othIndex--) { while (othIndex--) {
array = arrays[othIndex]; array = arrays[othIndex];
if (othIndex && iteratee) { if (othIndex && iteratee) {
array = arrayMap(array, baseUnary(iteratee)); array = arrayMap(array, valye => iteratee(value));
} }
maxLength = nativeMin(array.length, maxLength); maxLength = nativeMin(array.length, maxLength);
caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))

View File

@@ -2,7 +2,6 @@ import arrayMap from './_arrayMap.js';
import baseIteratee from './_baseIteratee.js'; import baseIteratee from './_baseIteratee.js';
import baseMap from './_baseMap.js'; import baseMap from './_baseMap.js';
import baseSortBy from './_baseSortBy.js'; import baseSortBy from './_baseSortBy.js';
import baseUnary from './_baseUnary.js';
import compareMultiple from './_compareMultiple.js'; import compareMultiple from './_compareMultiple.js';
import identity from './identity.js'; import identity from './identity.js';
@@ -17,7 +16,7 @@ import identity from './identity.js';
*/ */
function baseOrderBy(collection, iteratees, orders) { function baseOrderBy(collection, iteratees, orders) {
let index = -1; let index = -1;
iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(baseIteratee)); iteratees = arrayMap(iteratees.length ? iteratees : [identity], value => baseIteratee(value));
const result = baseMap(collection, (value, key, collection) => { const result = baseMap(collection, (value, key, collection) => {
const criteria = arrayMap(iteratees, iteratee => iteratee(value)); const criteria = arrayMap(iteratees, iteratee => iteratee(value));

View File

@@ -1,7 +1,6 @@
import arrayMap from './_arrayMap.js'; import arrayMap from './_arrayMap.js';
import baseIndexOf from './_baseIndexOf.js'; import baseIndexOf from './_baseIndexOf.js';
import baseIndexOfWith from './_baseIndexOfWith.js'; import baseIndexOfWith from './_baseIndexOfWith.js';
import baseUnary from './_baseUnary.js';
import copyArray from './_copyArray.js'; import copyArray from './_copyArray.js';
/** Used for built-in method references. */ /** Used for built-in method references. */
@@ -32,7 +31,7 @@ function basePullAll(array, values, iteratee, comparator) {
values = copyArray(values); values = copyArray(values);
} }
if (iteratee) { if (iteratee) {
seen = arrayMap(array, baseUnary(iteratee)); seen = arrayMap(array, value => iteratee(value));
} }
while (++index < length) { while (++index < length) {
let fromIndex = 0; let fromIndex = 0;

View File

@@ -1,12 +0,0 @@
/**
* The base implementation of `_.unary` without support for storing metadata.
*
* @private
* @param {Function} func The function to cap arguments for.
* @returns {Function} Returns the new capped function.
*/
function baseUnary(func) {
return value => func(value);
}
export default baseUnary;

View File

@@ -1,7 +1,6 @@
import apply from './_apply.js'; import apply from './_apply.js';
import arrayMap from './_arrayMap.js'; import arrayMap from './_arrayMap.js';
import baseIteratee from './_baseIteratee.js'; import baseIteratee from './_baseIteratee.js';
import baseUnary from './_baseUnary.js';
/** /**
* Creates a function like `_.over`. * Creates a function like `_.over`.
@@ -12,7 +11,7 @@ import baseUnary from './_baseUnary.js';
*/ */
function createOver(arrayFunc) { function createOver(arrayFunc) {
return (...iteratees) => { return (...iteratees) => {
iteratees = arrayMap(iteratees, baseUnary(baseIteratee)); iteratees = arrayMap(iteratees, iteratee => baseIteratee(iteratee));
return (...args) => { return (...args) => {
const thisArg = this; const thisArg = this;
return arrayFunc(iteratees, iteratee => apply(iteratee, thisArg, args)); return arrayFunc(iteratees, iteratee => apply(iteratee, thisArg, args));

View File

@@ -1,5 +1,4 @@
import baseIsArrayBuffer from './_baseIsArrayBuffer.js'; import baseIsArrayBuffer from './_baseIsArrayBuffer.js';
import baseUnary from './_baseUnary.js';
import nodeUtil from './_nodeUtil.js'; import nodeUtil from './_nodeUtil.js';
/* Node.js helper references. */ /* Node.js helper references. */
@@ -22,6 +21,8 @@ const nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer;
* _.isArrayBuffer(new Array(2)); * _.isArrayBuffer(new Array(2));
* // => false * // => false
*/ */
const isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer; const isArrayBuffer = nodeIsArrayBuffer
? value => nodeIsArrayBuffer(value)
: baseIsArrayBuffer;
export default isArrayBuffer; export default isArrayBuffer;

View File

@@ -1,5 +1,4 @@
import baseIsDate from './_baseIsDate.js'; import baseIsDate from './_baseIsDate.js';
import baseUnary from './_baseUnary.js';
import nodeUtil from './_nodeUtil.js'; import nodeUtil from './_nodeUtil.js';
/* Node.js helper references. */ /* Node.js helper references. */
@@ -22,6 +21,8 @@ const nodeIsDate = nodeUtil && nodeUtil.isDate;
* _.isDate('Mon April 23 2012'); * _.isDate('Mon April 23 2012');
* // => false * // => false
*/ */
const isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate; const isDate = nodeIsDate
? value => nodeIsDate(value)
: baseIsDate;
export default isDate; export default isDate;

View File

@@ -1,5 +1,4 @@
import baseIsMap from './_baseIsMap.js'; import baseIsMap from './_baseIsMap.js';
import baseUnary from './_baseUnary.js';
import nodeUtil from './_nodeUtil.js'; import nodeUtil from './_nodeUtil.js';
/* Node.js helper references. */ /* Node.js helper references. */
@@ -22,6 +21,8 @@ const nodeIsMap = nodeUtil && nodeUtil.isMap;
* _.isMap(new WeakMap); * _.isMap(new WeakMap);
* // => false * // => false
*/ */
const isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap; const isMap = nodeIsMap
? value => nodeIsMap(value)
: baseIsMap;
export default isMap; export default isMap;

View File

@@ -1,5 +1,4 @@
import baseIsRegExp from './_baseIsRegExp.js'; import baseIsRegExp from './_baseIsRegExp.js';
import baseUnary from './_baseUnary.js';
import nodeUtil from './_nodeUtil.js'; import nodeUtil from './_nodeUtil.js';
/* Node.js helper references. */ /* Node.js helper references. */
@@ -22,6 +21,8 @@ const nodeIsRegExp = nodeUtil && nodeUtil.isRegExp;
* _.isRegExp('/abc/'); * _.isRegExp('/abc/');
* // => false * // => false
*/ */
const isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp; const isRegExp = nodeIsRegExp
? value => nodeIsRegExp(value)
: baseIsRegExp;
export default isRegExp; export default isRegExp;

View File

@@ -1,5 +1,4 @@
import baseIsSet from './_baseIsSet.js'; import baseIsSet from './_baseIsSet.js';
import baseUnary from './_baseUnary.js';
import nodeUtil from './_nodeUtil.js'; import nodeUtil from './_nodeUtil.js';
/* Node.js helper references. */ /* Node.js helper references. */
@@ -22,6 +21,8 @@ const nodeIsSet = nodeUtil && nodeUtil.isSet;
* _.isSet(new WeakSet); * _.isSet(new WeakSet);
* // => false * // => false
*/ */
const isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet; const isSet = nodeIsSet
? value => nodeIsSet(value)
: baseIsSet;
export default isSet; export default isSet;

View File

@@ -1,5 +1,4 @@
import baseIsTypedArray from './_baseIsTypedArray.js'; import baseIsTypedArray from './_baseIsTypedArray.js';
import baseUnary from './_baseUnary.js';
import nodeUtil from './_nodeUtil.js'; import nodeUtil from './_nodeUtil.js';
/* Node.js helper references. */ /* Node.js helper references. */
@@ -22,6 +21,8 @@ const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
* _.isTypedArray([]); * _.isTypedArray([]);
* // => false * // => false
*/ */
const isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; const isTypedArray = nodeIsTypedArray
? value => nodeIsTypedArray(value)
: baseIsTypedArray;
export default isTypedArray; export default isTypedArray;

View File

@@ -2,8 +2,6 @@ import apply from './_apply.js';
import arrayMap from './_arrayMap.js'; import arrayMap from './_arrayMap.js';
import baseFlatten from './_baseFlatten.js'; import baseFlatten from './_baseFlatten.js';
import baseIteratee from './_baseIteratee.js'; import baseIteratee from './_baseIteratee.js';
import baseUnary from './_baseUnary.js';
import isArray from './isArray.js';
/* Built-in method references for those with the same name as other `lodash` methods. */ /* Built-in method references for those with the same name as other `lodash` methods. */
const nativeMin = Math.min; const nativeMin = Math.min;
@@ -40,10 +38,7 @@ const nativeMin = Math.min;
* // => [100, 10] * // => [100, 10]
*/ */
function overArgs(func, ...transforms) { function overArgs(func, ...transforms) {
transforms = (transforms.length == 1 && isArray(transforms[0])) transforms = arrayMap(transforms, transform => baseIteratee(transform));
? arrayMap(transforms[0], baseUnary(baseIteratee))
: arrayMap(baseFlatten(transforms, 1), baseUnary(baseIteratee));
const funcsLength = transforms.length; const funcsLength = transforms.length;
return function(...args) { return function(...args) {
let index = -1; let index = -1;

View File

@@ -1,22 +0,0 @@
import ary from './ary.js';
/**
* Creates a function that accepts up to one argument, ignoring any
* additional arguments.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Function
* @param {Function} func The function to cap arguments for.
* @returns {Function} Returns the new capped function.
* @example
*
* _.map(['6', '8', '10'], _.unary(parseInt));
* // => [6, 8, 10]
*/
function unary(func) {
return ary(func, 1);
}
export default unary;

View File

@@ -21,7 +21,8 @@ import isArrayLikeObject from './isArrayLikeObject.js';
* _.without([2, 1, 2, 3], 1, 2); * _.without([2, 1, 2, 3], 1, 2);
* // => [3] * // => [3]
*/ */
const without = (array, ...values) => function without(array, ...values) {
isArrayLikeObject(array) ? baseDifference(array, values) : []; return isArrayLikeObject(array) ? baseDifference(array, values) : [];
}
export default without; export default without;