From 4d185ae7b5ffa1041760b59fb9e6f8a9092b9a9c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 13 Mar 2016 15:13:39 -0700 Subject: [PATCH] Add `fp.restFrom` and `fp.spreadFrom`. --- fp/_mapping.js | 17 ++++++++++------- test/test-fp.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/fp/_mapping.js b/fp/_mapping.js index 952b80a37..26bde3856 100644 --- a/fp/_mapping.js +++ b/fp/_mapping.js @@ -59,13 +59,14 @@ exports.aryMethod = { 'map', 'mapKeys', 'mapValues', 'matchesProperty', 'maxBy', 'merge', 'minBy', 'omit', 'omitBy', 'overArgs', 'pad', 'padEnd', 'padStart', 'parseInt', 'partial', 'partialRight', 'partition', 'pick', 'pickBy', 'pull', 'pullAll', 'pullAt', - 'random', 'range', 'rangeRight', 'rearg', 'reject', 'remove', 'repeat', 'result', - 'sampleSize', 'some', 'sortBy', 'sortedIndex', 'sortedIndexOf', 'sortedLastIndex', - 'sortedLastIndexOf', 'sortedUniqBy', 'split', 'startsWith', 'subtract', 'sumBy', - 'take', 'takeRight', 'takeRightWhile', 'takeWhile', 'tap', 'throttle', 'thru', - 'times', 'trimChars', 'trimCharsEnd', 'trimCharsStart', 'truncate', 'union', - 'uniqBy', 'uniqWith', 'unset', 'unzipWith', 'without', 'wrap', 'xor', 'zip', - 'zipObject', 'zipObjectDeep' + 'random', 'range', 'rangeRight', 'rearg', 'reject', 'remove', 'repeat', + 'restFrom', 'result', 'sampleSize', 'some', 'sortBy', 'sortedIndex', + 'sortedIndexOf', 'sortedLastIndex', 'sortedLastIndexOf', 'sortedUniqBy', + 'split', 'spreadFrom', 'startsWith', 'subtract', 'sumBy', 'take', 'takeRight', + 'takeRightWhile', 'takeWhile', 'tap', 'throttle', 'thru', 'times', 'trimChars', + 'trimCharsEnd', 'trimCharsStart', 'truncate', 'union', 'uniqBy', 'uniqWith', + 'unset', 'unzipWith', 'without', 'wrap', 'xor', 'zip', 'zipObject', + 'zipObjectDeep' ], '3': [ 'assignInWith', 'assignWith', 'clamp', 'differenceBy', 'differenceWith', @@ -219,6 +220,8 @@ exports.remap = { 'curryN': 'curry', 'curryRightN': 'curryRight', 'getOr': 'get', + 'restFrom': 'rest', + 'spreadFrom': 'spread', 'trimChars': 'trim', 'trimCharsEnd': 'trimEnd', 'trimCharsStart': 'trimStart' diff --git a/test/test-fp.js b/test/test-fp.js index 6e2e6558c..5bc2bcd33 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -1447,6 +1447,22 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('fp.restFrom'); + + (function() { + QUnit.test('should accept a `start` param', function(assert) { + assert.expect(1); + + var actual = fp.restFrom(2)(function() { + return slice.call(arguments); + })('a', 'b', 'c', 'd'); + + assert.deepEqual(actual, ['a', 'b', ['c', 'd']]); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('fp.runInContext'); (function() { @@ -1466,6 +1482,22 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('fp.spreadFrom'); + + (function() { + QUnit.test('should accept a `start` param', function(assert) { + assert.expect(1); + + var actual = fp.spreadFrom(2)(function() { + return slice.call(arguments); + })('a', 'b', ['c', 'd']); + + assert.deepEqual(actual, ['a', 'b', 'c', 'd']); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('fp.trimChars'); _.each(['trimChars', 'trimCharsStart', 'trimCharsEnd'], function(methodName, index) {