From aacfefc7524e1c647b39efa605f1eca1f6da80d5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 9 Jan 2017 15:36:35 -0800 Subject: [PATCH] Remove remaining rest helper use. --- _castRest.js | 14 -------------- _createAssigner.js | 5 ++--- _createFlow.js | 5 ++--- _createOver.js | 10 ++++------ _flatRest.js | 16 ---------------- _overRest.js | 36 ------------------------------------ at.js | 5 +++-- attempt.js | 5 ++--- bind.js | 5 ++--- bindAll.js | 5 ++--- bindKey.js | 5 ++--- cond.js | 5 ++--- defaults.js | 5 ++--- defaultsDeep.js | 5 ++--- invoke.js | 5 +++-- method.js | 5 +++-- methodOf.js | 5 +++-- nthArg.js | 3 +-- pick.js | 5 +++-- pull.js | 5 +++-- pullAt.js | 9 ++++----- rearg.js | 5 +++-- rest.js | 40 ---------------------------------------- spread.js | 5 ++--- zip.js | 5 +++-- 25 files changed, 53 insertions(+), 165 deletions(-) delete mode 100644 _castRest.js delete mode 100644 _flatRest.js delete mode 100644 _overRest.js delete mode 100644 rest.js diff --git a/_castRest.js b/_castRest.js deleted file mode 100644 index e8e7ddf536..0000000000 --- a/_castRest.js +++ /dev/null @@ -1,14 +0,0 @@ -import baseRest from './_baseRest.js'; - -/** - * A `baseRest` alias which can be replaced with `identity` by module - * replacement plugins. - * - * @private - * @type {Function} - * @param {Function} func The function to apply a rest parameter to. - * @returns {Function} Returns the new function. - */ -const castRest = baseRest; - -export default castRest; diff --git a/_createAssigner.js b/_createAssigner.js index 9c71c0bbd8..1d691ba46d 100644 --- a/_createAssigner.js +++ b/_createAssigner.js @@ -1,4 +1,3 @@ -import baseRest from './_baseRest.js'; import isIterateeCall from './_isIterateeCall.js'; /** @@ -9,7 +8,7 @@ import isIterateeCall from './_isIterateeCall.js'; * @returns {Function} Returns the new assigner function. */ function createAssigner(assigner) { - return baseRest((object, sources) => { + return (object, ...sources) => { let index = -1; let length = sources.length; let customizer = length > 1 ? sources[length - 1] : undefined; @@ -31,7 +30,7 @@ function createAssigner(assigner) { } } return object; - }); + }; } export default createAssigner; diff --git a/_createFlow.js b/_createFlow.js index 131a788c64..6cabc3b27f 100644 --- a/_createFlow.js +++ b/_createFlow.js @@ -1,5 +1,4 @@ import LodashWrapper from './_LodashWrapper.js'; -import flatRest from './_flatRest.js'; import getData from './_getData.js'; import getFuncName from './_getFuncName.js'; import isArray from './isArray.js'; @@ -22,7 +21,7 @@ const WRAP_REARG_FLAG = 256; * @returns {Function} Returns the new flow function. */ function createFlow(fromRight) { - return flatRest(funcs => { + return (...funcs) => { const length = funcs.length; const prereq = LodashWrapper.prototype.thru; @@ -74,7 +73,7 @@ function createFlow(fromRight) { } return result; }; - }); + }; } export default createFlow; diff --git a/_createOver.js b/_createOver.js index 4093c5fd65..1e60bea8e7 100644 --- a/_createOver.js +++ b/_createOver.js @@ -1,9 +1,7 @@ import apply from './_apply.js'; import arrayMap from './_arrayMap.js'; import baseIteratee from './_baseIteratee.js'; -import baseRest from './_baseRest.js'; import baseUnary from './_baseUnary.js'; -import flatRest from './_flatRest.js'; /** * Creates a function like `_.over`. @@ -13,13 +11,13 @@ import flatRest from './_flatRest.js'; * @returns {Function} Returns the new over function. */ function createOver(arrayFunc) { - return flatRest(iteratees => { + return (...iteratees) => { iteratees = arrayMap(iteratees, baseUnary(baseIteratee)); - return baseRest(function(args) { + return (...args) => { const thisArg = this; return arrayFunc(iteratees, iteratee => apply(iteratee, thisArg, args)); - }); - }); + }; + }; } export default createOver; diff --git a/_flatRest.js b/_flatRest.js deleted file mode 100644 index b9122fb642..0000000000 --- a/_flatRest.js +++ /dev/null @@ -1,16 +0,0 @@ -import flatten from './flatten.js'; -import overRest from './_overRest.js'; -import setToString from './_setToString.js'; - -/** - * A specialized version of `baseRest` which flattens the rest array. - * - * @private - * @param {Function} func The function to apply a rest parameter to. - * @returns {Function} Returns the new function. - */ -function flatRest(func) { - return setToString(overRest(func, undefined, flatten), `${ func }`); -} - -export default flatRest; diff --git a/_overRest.js b/_overRest.js deleted file mode 100644 index 0634b987e0..0000000000 --- a/_overRest.js +++ /dev/null @@ -1,36 +0,0 @@ -import apply from './_apply.js'; - -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMax = Math.max; - -/** - * A specialized version of `baseRest` which transforms the rest array. - * - * @private - * @param {Function} func The function to apply a rest parameter to. - * @param {number} [start=func.length-1] The start position of the rest parameter. - * @param {Function} transform The rest array transform. - * @returns {Function} Returns the new function. - */ -function overRest(func, start, transform) { - start = nativeMax(start === undefined ? (func.length - 1) : start, 0); - return function() { - const args = arguments; - let index = -1; - const length = nativeMax(args.length - start, 0); - const array = Array(length); - - while (++index < length) { - array[index] = args[start + index]; - } - index = -1; - const otherArgs = Array(start + 1); - while (++index < start) { - otherArgs[index] = args[index]; - } - otherArgs[start] = transform(array); - return apply(func, this, otherArgs); - }; -} - -export default overRest; diff --git a/at.js b/at.js index aa69cc0172..387ac1a467 100644 --- a/at.js +++ b/at.js @@ -1,5 +1,4 @@ import baseAt from './_baseAt.js'; -import flatRest from './_flatRest.js'; /** * Creates an array of values corresponding to `paths` of `object`. @@ -18,6 +17,8 @@ import flatRest from './_flatRest.js'; * _.at(object, ['a[0].b.c', 'a[1]']); * // => [3, 4] */ -const at = flatRest(baseAt); +function at(...paths) { + return baseAt(paths); +} export default at; diff --git a/attempt.js b/attempt.js index f297e9c6c0..6a39e99f08 100644 --- a/attempt.js +++ b/attempt.js @@ -1,5 +1,4 @@ import apply from './_apply.js'; -import baseRest from './_baseRest.js'; import isError from './isError.js'; /** @@ -24,12 +23,12 @@ import isError from './isError.js'; * elements = []; * } */ -const attempt = baseRest((func, args) => { +function attempt(func, ...args) { try { return apply(func, undefined, args); } catch (e) { return isError(e) ? e : new Error(e); } -}); +} export default attempt; diff --git a/bind.js b/bind.js index 8031ae9ffc..c7b6dea220 100644 --- a/bind.js +++ b/bind.js @@ -1,4 +1,3 @@ -import baseRest from './_baseRest.js'; import createWrap from './_createWrap.js'; import getHolder from './_getHolder.js'; import replaceHolders from './_replaceHolders.js'; @@ -42,7 +41,7 @@ const WRAP_PARTIAL_FLAG = 32; * bound('hi'); * // => 'hi fred!' */ -const bind = baseRest((func, thisArg, partials) => { +function bind(func, thisArg, ...partials) { let holders; let bitmask = WRAP_BIND_FLAG; if (partials.length) { @@ -50,7 +49,7 @@ const bind = baseRest((func, thisArg, partials) => { bitmask |= WRAP_PARTIAL_FLAG; } return createWrap(func, bitmask, thisArg, partials, holders); -}); +} // Assign default placeholders. bind.placeholder = {}; diff --git a/bindAll.js b/bindAll.js index 1bcfe55a73..ba9f07f409 100644 --- a/bindAll.js +++ b/bindAll.js @@ -1,7 +1,6 @@ import arrayEach from './_arrayEach.js'; import baseAssignValue from './_baseAssignValue.js'; import bind from './bind.js'; -import flatRest from './_flatRest.js'; import toKey from './_toKey.js'; /** @@ -30,12 +29,12 @@ import toKey from './_toKey.js'; * jQuery(element).on('click', view.click); * // => Logs 'clicked docs' when clicked. */ -const bindAll = flatRest((object, methodNames) => { +function bindAll(object, ...methodNames) { arrayEach(methodNames, key => { key = toKey(key); baseAssignValue(object, key, bind(object[key], object)); }); return object; -}); +} export default bindAll; diff --git a/bindKey.js b/bindKey.js index 0d56eba919..ac9cec1722 100644 --- a/bindKey.js +++ b/bindKey.js @@ -1,4 +1,3 @@ -import baseRest from './_baseRest.js'; import createWrap from './_createWrap.js'; import getHolder from './_getHolder.js'; import replaceHolders from './_replaceHolders.js'; @@ -53,7 +52,7 @@ const WRAP_PARTIAL_FLAG = 32; * bound('hi'); * // => 'hiya fred!' */ -const bindKey = baseRest((object, key, partials) => { +function bindKey(object, key, ...partials) { let holders; let bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG; if (partials.length) { @@ -61,7 +60,7 @@ const bindKey = baseRest((object, key, partials) => { bitmask |= WRAP_PARTIAL_FLAG; } return createWrap(key, bitmask, object, partials, holders); -}); +} // Assign default placeholders. bindKey.placeholder = {}; diff --git a/cond.js b/cond.js index a874c0c0f0..15075e8897 100644 --- a/cond.js +++ b/cond.js @@ -1,7 +1,6 @@ import apply from './_apply.js'; import arrayMap from './_arrayMap.js'; import baseIteratee from './_baseIteratee.js'; -import baseRest from './_baseRest.js'; /** Error message constants. */ const FUNC_ERROR_TEXT = 'Expected a function'; @@ -46,7 +45,7 @@ function cond(pairs) { return [toIteratee(pair[0]), pair[1]]; }); - return baseRest(function(args) { + return (...args) => { let index = -1; while (++index < length) { const pair = pairs[index]; @@ -54,7 +53,7 @@ function cond(pairs) { return apply(pair[1], this, args); } } - }); + }; } export default cond; diff --git a/defaults.js b/defaults.js index 7a0c949b93..1e41a4750d 100644 --- a/defaults.js +++ b/defaults.js @@ -1,6 +1,5 @@ import apply from './_apply.js'; import assignInWith from './assignInWith.js'; -import baseRest from './_baseRest.js'; import customDefaultsAssignIn from './_customDefaultsAssignIn.js'; /** @@ -24,9 +23,9 @@ import customDefaultsAssignIn from './_customDefaultsAssignIn.js'; * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); * // => { 'a': 1, 'b': 2 } */ -const defaults = baseRest(args => { +function defaults(...args) { args.push(undefined, customDefaultsAssignIn); return apply(assignInWith, undefined, args); -}); +} export default defaults; diff --git a/defaultsDeep.js b/defaultsDeep.js index d972ea78a3..6ca4344074 100644 --- a/defaultsDeep.js +++ b/defaultsDeep.js @@ -1,5 +1,4 @@ import apply from './_apply.js'; -import baseRest from './_baseRest.js'; import customDefaultsMerge from './_customDefaultsMerge.js'; import mergeWith from './mergeWith.js'; @@ -22,9 +21,9 @@ import mergeWith from './mergeWith.js'; * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }); * // => { 'a': { 'b': 2, 'c': 3 } } */ -const defaultsDeep = baseRest(args => { +function defaultsDeep(...args) { args.push(undefined, customDefaultsMerge); return apply(mergeWith, undefined, args); -}); +} export default defaultsDeep; diff --git a/invoke.js b/invoke.js index 645dcaf8c9..5cf47595e8 100644 --- a/invoke.js +++ b/invoke.js @@ -1,5 +1,4 @@ import baseInvoke from './_baseInvoke.js'; -import baseRest from './_baseRest.js'; /** * Invokes the method at `path` of `object`. @@ -19,6 +18,8 @@ import baseRest from './_baseRest.js'; * _.invoke(object, 'a[0].b.c.slice', 1, 3); * // => [2, 3] */ -const invoke = baseRest(baseInvoke); +function invoke(object, path, ...args) { + return baseInvoke(object, path, args); +} export default invoke; diff --git a/method.js b/method.js index 2ac6328450..d8725cae60 100644 --- a/method.js +++ b/method.js @@ -1,5 +1,4 @@ import baseInvoke from './_baseInvoke.js'; -import baseRest from './_baseRest.js'; /** * Creates a function that invokes the method at `path` of a given object. @@ -25,6 +24,8 @@ import baseRest from './_baseRest.js'; * _.map(objects, _.method(['a', 'b'])); * // => [2, 1] */ -const method = baseRest((path, args) => object => baseInvoke(object, path, args)); +function method(path, ...args) { + return object => baseInvoke(object, path, args); +} export default method; diff --git a/methodOf.js b/methodOf.js index c37781eedd..90eceecb3d 100644 --- a/methodOf.js +++ b/methodOf.js @@ -1,5 +1,4 @@ import baseInvoke from './_baseInvoke.js'; -import baseRest from './_baseRest.js'; /** * The opposite of `_.method`; this method creates a function that invokes @@ -24,6 +23,8 @@ import baseRest from './_baseRest.js'; * _.map([['a', '2'], ['c', '0']], _.methodOf(object)); * // => [2, 0] */ -const methodOf = baseRest((object, args) => path => baseInvoke(object, path, args)); +function methodOf(object, ...args) { + return path => baseInvoke(object, path, args); +} export default methodOf; diff --git a/nthArg.js b/nthArg.js index 76f4749411..574e0719cd 100644 --- a/nthArg.js +++ b/nthArg.js @@ -1,5 +1,4 @@ import baseNth from './_baseNth.js'; -import baseRest from './_baseRest.js'; import toInteger from './toInteger.js'; /** @@ -24,7 +23,7 @@ import toInteger from './toInteger.js'; */ function nthArg(n) { n = toInteger(n); - return baseRest(args => baseNth(args, n)); + return (...args) => baseNth(args, n); } export default nthArg; diff --git a/pick.js b/pick.js index eb922624fd..fa4ffae5a3 100644 --- a/pick.js +++ b/pick.js @@ -1,5 +1,4 @@ import basePick from './_basePick.js'; -import flatRest from './_flatRest.js'; /** * Creates an object composed of the picked `object` properties. @@ -18,6 +17,8 @@ import flatRest from './_flatRest.js'; * _.pick(object, ['a', 'c']); * // => { 'a': 1, 'c': 3 } */ -const pick = flatRest((object, paths) => object == null ? {} : basePick(object, paths)); +function pick(object, ...paths) { + return object == null ? {} : basePick(object, paths); +} export default pick; diff --git a/pull.js b/pull.js index b125a0ea4f..f4e1404ff9 100644 --- a/pull.js +++ b/pull.js @@ -1,4 +1,3 @@ -import baseRest from './_baseRest.js'; import pullAll from './pullAll.js'; /** @@ -24,6 +23,8 @@ import pullAll from './pullAll.js'; * console.log(array); * // => ['b', 'b'] */ -const pull = baseRest(pullAll); +function pull(array, ...values) { + return pullAll(array, values); +} export default pull; diff --git a/pullAt.js b/pullAt.js index d7c4e59052..7276900852 100644 --- a/pullAt.js +++ b/pullAt.js @@ -2,7 +2,6 @@ import arrayMap from './_arrayMap.js'; import baseAt from './_baseAt.js'; import basePullAt from './_basePullAt.js'; import compareAscending from './_compareAscending.js'; -import flatRest from './_flatRest.js'; import isIndex from './_isIndex.js'; /** @@ -29,12 +28,12 @@ import isIndex from './_isIndex.js'; * console.log(pulled); * // => ['b', 'd'] */ -const pullAt = flatRest((array, indexes) => { - const length = array == null ? 0 : array.length, result = baseAt(array, indexes); +function pullAt(array, ...indexes) { + const length = array == null ? 0 : array.length; + const result = baseAt(array, indexes); basePullAt(array, arrayMap(indexes, index => isIndex(index, length) ? +index : index).sort(compareAscending)); - return result; -}); +} export default pullAt; diff --git a/rearg.js b/rearg.js index 91984dd7f8..36c7147b6c 100644 --- a/rearg.js +++ b/rearg.js @@ -1,5 +1,4 @@ import createWrap from './_createWrap.js'; -import flatRest from './_flatRest.js'; /** Used to compose bitmasks for function metadata. */ const WRAP_REARG_FLAG = 256; @@ -26,6 +25,8 @@ const WRAP_REARG_FLAG = 256; * rearged('b', 'c', 'a') * // => ['a', 'b', 'c'] */ -const rearg = flatRest((func, indexes) => createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes)); +function rearg(func, ...indexes) { + return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes); +} export default rearg; diff --git a/rest.js b/rest.js deleted file mode 100644 index cad060b27b..0000000000 --- a/rest.js +++ /dev/null @@ -1,40 +0,0 @@ -import baseRest from './_baseRest.js'; -import toInteger from './toInteger.js'; - -/** Error message constants. */ -const FUNC_ERROR_TEXT = 'Expected a function'; - -/** - * Creates a function that invokes `func` with the `this` binding of the - * created function and arguments from `start` and beyond provided as - * an array. - * - * **Note:** This method is based on the - * [rest parameter](https://mdn.io/rest_parameters). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Function - * @param {Function} func The function to apply a rest parameter to. - * @param {number} [start=func.length-1] The start position of the rest parameter. - * @returns {Function} Returns the new function. - * @example - * - * var say = _.rest(function(what, names) { - * return what + ' ' + _.initial(names).join(', ') + - * (_.size(names) > 1 ? ', & ' : '') + _.last(names); - * }); - * - * say('hello', 'fred', 'barney', 'pebbles'); - * // => 'hello fred, barney, & pebbles' - */ -function rest(func, start) { - if (typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); - } - start = start === undefined ? start : toInteger(start); - return baseRest(func, start); -} - -export default rest; diff --git a/spread.js b/spread.js index 93554d2dd7..f6af9acb76 100644 --- a/spread.js +++ b/spread.js @@ -1,6 +1,5 @@ import apply from './_apply.js'; import arrayPush from './_arrayPush.js'; -import baseRest from './_baseRest.js'; import castSlice from './_castSlice.js'; import toInteger from './toInteger.js'; @@ -49,7 +48,7 @@ function spread(func, start) { throw new TypeError(FUNC_ERROR_TEXT); } start = start == null ? 0 : nativeMax(toInteger(start), 0); - return baseRest(function(args) { + return (...args) => { const array = args[start]; const otherArgs = castSlice(args, 0, start); @@ -57,7 +56,7 @@ function spread(func, start) { arrayPush(otherArgs, array); } return apply(func, this, otherArgs); - }); + }; } export default spread; diff --git a/zip.js b/zip.js index ebe627aee1..52fbab8bb8 100644 --- a/zip.js +++ b/zip.js @@ -1,4 +1,3 @@ -import baseRest from './_baseRest.js'; import unzip from './unzip.js'; /** @@ -17,6 +16,8 @@ import unzip from './unzip.js'; * _.zip(['a', 'b'], [1, 2], [true, false]); * // => [['a', 1, true], ['b', 2, false]] */ -const zip = baseRest(unzip); +function zip(...arays) { + return unzip(arrays); +} export default zip;