mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Ensure fp.nthArg returns a curried function.
This commit is contained in:
@@ -143,6 +143,7 @@ function baseConvert(util, name, func, options) {
|
|||||||
'keys': util.keys,
|
'keys': util.keys,
|
||||||
'rearg': util.rearg,
|
'rearg': util.rearg,
|
||||||
'spread': util.spread,
|
'spread': util.spread,
|
||||||
|
'toInteger': util.toInteger,
|
||||||
'toPath': util.toPath
|
'toPath': util.toPath
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -156,6 +157,7 @@ function baseConvert(util, name, func, options) {
|
|||||||
keys = helpers.keys,
|
keys = helpers.keys,
|
||||||
rearg = helpers.rearg,
|
rearg = helpers.rearg,
|
||||||
spread = helpers.spread,
|
spread = helpers.spread,
|
||||||
|
toInteger = helpers.toInteger,
|
||||||
toPath = helpers.toPath;
|
toPath = helpers.toPath;
|
||||||
|
|
||||||
var aryMethodKeys = keys(mapping.aryMethod);
|
var aryMethodKeys = keys(mapping.aryMethod);
|
||||||
@@ -209,10 +211,16 @@ function baseConvert(util, name, func, options) {
|
|||||||
return func;
|
return func;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
'nthArg': function(nthArg) {
|
||||||
|
return function(n) {
|
||||||
|
var arity = n < 0 ? 1 : (toInteger(n) + 1);
|
||||||
|
return curry(nthArg(n), arity);
|
||||||
|
};
|
||||||
|
},
|
||||||
'rearg': function(rearg) {
|
'rearg': function(rearg) {
|
||||||
return function(func, indexes) {
|
return function(func, indexes) {
|
||||||
var n = indexes ? indexes.length : 0;
|
var arity = indexes ? indexes.length : 0;
|
||||||
return curry(rearg(func, indexes), n);
|
return curry(rearg(func, indexes), arity);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
'runInContext': function(runInContext) {
|
'runInContext': function(runInContext) {
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ exports.aryMethod = {
|
|||||||
'1': [
|
'1': [
|
||||||
'assignAll', 'assignInAll', 'attempt', 'castArray', 'ceil', 'create',
|
'assignAll', 'assignInAll', 'attempt', 'castArray', 'ceil', 'create',
|
||||||
'curry', 'curryRight', 'defaultsAll', 'defaultsDeepAll', 'floor', 'flow',
|
'curry', 'curryRight', 'defaultsAll', 'defaultsDeepAll', 'floor', 'flow',
|
||||||
'flowRight', 'fromPairs', 'invert', 'iteratee', 'memoize', 'method',
|
'flowRight', 'fromPairs', 'invert', 'iteratee', 'memoize', 'method', 'mergeAll',
|
||||||
'mergeAll', 'methodOf', 'mixin', 'over', 'overEvery', 'overSome', 'rest',
|
'methodOf', 'mixin', 'nthArg', 'over', 'overEvery', 'overSome','rest', 'reverse',
|
||||||
'reverse', 'round', 'runInContext', 'spread', 'template', 'trim', 'trimEnd',
|
'round', 'runInContext', 'spread', 'template', 'trim', 'trimEnd', 'trimStart',
|
||||||
'trimStart', 'uniqueId', 'words', 'zipAll'
|
'uniqueId', 'words', 'zipAll'
|
||||||
],
|
],
|
||||||
'2': [
|
'2': [
|
||||||
'add', 'after', 'ary', 'assign', 'assignAllWith', 'assignIn', 'assignInAllWith',
|
'add', 'after', 'ary', 'assign', 'assignAllWith', 'assignIn', 'assignInAllWith',
|
||||||
|
|||||||
@@ -10,5 +10,6 @@ module.exports = {
|
|||||||
'keys': require('../_baseKeys'),
|
'keys': require('../_baseKeys'),
|
||||||
'rearg': require('../rearg'),
|
'rearg': require('../rearg'),
|
||||||
'spread': require('../spread'),
|
'spread': require('../spread'),
|
||||||
|
'toInteger': require('../toInteger'),
|
||||||
'toPath': require('../toPath')
|
'toPath': require('../toPath')
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -371,7 +371,7 @@
|
|||||||
'method', 'methodOf', 'rest', 'runInContext'
|
'method', 'methodOf', 'rest', 'runInContext'
|
||||||
];
|
];
|
||||||
|
|
||||||
var exceptions = funcMethods.concat('mixin', 'template'),
|
var exceptions = funcMethods.concat('mixin', 'nthArg', 'template'),
|
||||||
expected = _.map(mapping.aryMethod[1], _.constant(true));
|
expected = _.map(mapping.aryMethod[1], _.constant(true));
|
||||||
|
|
||||||
var actual = _.map(mapping.aryMethod[1], function(methodName) {
|
var actual = _.map(mapping.aryMethod[1], function(methodName) {
|
||||||
@@ -1588,6 +1588,22 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('fp.nthArg');
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
QUnit.test('should return a curried function', function(assert) {
|
||||||
|
assert.expect(2);
|
||||||
|
|
||||||
|
var func = fp.nthArg(1);
|
||||||
|
assert.strictEqual(func(1)(2), 2);
|
||||||
|
|
||||||
|
func = fp.nthArg(-1);
|
||||||
|
assert.strictEqual(func(1), 1);
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('fp.over');
|
QUnit.module('fp.over');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
@@ -1793,7 +1809,7 @@
|
|||||||
assert.deepEqual(rearged('c', 'a', 'b'), ['a', 'b', 'c']);
|
assert.deepEqual(rearged('c', 'a', 'b'), ['a', 'b', 'c']);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should curry the rearged function', function(assert) {
|
QUnit.test('should return a curried function', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var rearged = fp.rearg([1, 2, 0], fn);
|
var rearged = fp.rearg([1, 2, 0], fn);
|
||||||
|
|||||||
Reference in New Issue
Block a user