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

View File

@@ -2,7 +2,6 @@ import SetCache from './_SetCache.js';
import arrayIncludes from './_arrayIncludes.js';
import arrayIncludesWith from './_arrayIncludesWith.js';
import arrayMap from './_arrayMap.js';
import baseUnary from './_baseUnary.js';
import cacheHas from './_cacheHas.js';
/* 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--) {
array = arrays[othIndex];
if (othIndex && iteratee) {
array = arrayMap(array, baseUnary(iteratee));
array = arrayMap(array, valye => iteratee(value));
}
maxLength = nativeMin(array.length, maxLength);
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 baseMap from './_baseMap.js';
import baseSortBy from './_baseSortBy.js';
import baseUnary from './_baseUnary.js';
import compareMultiple from './_compareMultiple.js';
import identity from './identity.js';
@@ -17,7 +16,7 @@ import identity from './identity.js';
*/
function baseOrderBy(collection, iteratees, orders) {
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 criteria = arrayMap(iteratees, iteratee => iteratee(value));

View File

@@ -1,7 +1,6 @@
import arrayMap from './_arrayMap.js';
import baseIndexOf from './_baseIndexOf.js';
import baseIndexOfWith from './_baseIndexOfWith.js';
import baseUnary from './_baseUnary.js';
import copyArray from './_copyArray.js';
/** Used for built-in method references. */
@@ -32,7 +31,7 @@ function basePullAll(array, values, iteratee, comparator) {
values = copyArray(values);
}
if (iteratee) {
seen = arrayMap(array, baseUnary(iteratee));
seen = arrayMap(array, value => iteratee(value));
}
while (++index < length) {
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 arrayMap from './_arrayMap.js';
import baseIteratee from './_baseIteratee.js';
import baseUnary from './_baseUnary.js';
/**
* Creates a function like `_.over`.
@@ -12,7 +11,7 @@ import baseUnary from './_baseUnary.js';
*/
function createOver(arrayFunc) {
return (...iteratees) => {
iteratees = arrayMap(iteratees, baseUnary(baseIteratee));
iteratees = arrayMap(iteratees, iteratee => baseIteratee(iteratee));
return (...args) => {
const thisArg = this;
return arrayFunc(iteratees, iteratee => apply(iteratee, thisArg, args));

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,8 +2,6 @@ import apply from './_apply.js';
import arrayMap from './_arrayMap.js';
import baseFlatten from './_baseFlatten.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. */
const nativeMin = Math.min;
@@ -40,10 +38,7 @@ const nativeMin = Math.min;
* // => [100, 10]
*/
function overArgs(func, ...transforms) {
transforms = (transforms.length == 1 && isArray(transforms[0]))
? arrayMap(transforms[0], baseUnary(baseIteratee))
: arrayMap(baseFlatten(transforms, 1), baseUnary(baseIteratee));
transforms = arrayMap(transforms, transform => baseIteratee(transform));
const funcsLength = transforms.length;
return function(...args) {
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);
* // => [3]
*/
const without = (array, ...values) =>
isArrayLikeObject(array) ? baseDifference(array, values) : [];
function without(array, ...values) {
return isArrayLikeObject(array) ? baseDifference(array, values) : [];
}
export default without;