mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 03:47:50 +00:00
Add iterateeRearg fp mapping back for mapKeys.
This commit is contained in:
@@ -67,6 +67,12 @@ function baseConvert(util, name, func, options) {
|
|||||||
|
|
||||||
var aryMethodKeys = keys(mapping.aryMethod);
|
var aryMethodKeys = keys(mapping.aryMethod);
|
||||||
|
|
||||||
|
var baseArity = function(func, n) {
|
||||||
|
return n == 2
|
||||||
|
? function(a, b) { return func.apply(undefined, arguments); }
|
||||||
|
: function(a) { return func.apply(undefined, arguments); };
|
||||||
|
};
|
||||||
|
|
||||||
var baseAry = function(func, n) {
|
var baseAry = function(func, n) {
|
||||||
return n == 2
|
return n == 2
|
||||||
? function(a, b) { return func(a, b); }
|
? function(a, b) { return func(a, b); }
|
||||||
@@ -107,9 +113,14 @@ function baseConvert(util, name, func, options) {
|
|||||||
|
|
||||||
var iterateeAry = function(func, n) {
|
var iterateeAry = function(func, n) {
|
||||||
return overArg(func, function(func) {
|
return overArg(func, function(func) {
|
||||||
return typeof func == 'function'
|
return typeof func == 'function' ? baseAry(func, n) : func;
|
||||||
? baseAry(func, n)
|
});
|
||||||
: func;
|
};
|
||||||
|
|
||||||
|
var iterateeRearg = function(func, indexes) {
|
||||||
|
return overArg(func, function(func) {
|
||||||
|
var n = indexes.length;
|
||||||
|
return baseArity(rearg(baseAry(func, n), indexes), n);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -212,6 +223,7 @@ function baseConvert(util, name, func, options) {
|
|||||||
each(mapping.aryMethod[aryKey], function(otherName) {
|
each(mapping.aryMethod[aryKey], function(otherName) {
|
||||||
if (name == otherName) {
|
if (name == otherName) {
|
||||||
var aryN = !isLib && mapping.iterateeAry[name],
|
var aryN = !isLib && mapping.iterateeAry[name],
|
||||||
|
reargIndexes = mapping.iterateeRearg[name],
|
||||||
spreadStart = mapping.methodSpread[name];
|
spreadStart = mapping.methodSpread[name];
|
||||||
|
|
||||||
result = wrapped;
|
result = wrapped;
|
||||||
@@ -223,8 +235,12 @@ function baseConvert(util, name, func, options) {
|
|||||||
if (config.rearg && aryKey > 1 && (forceRearg || !mapping.skipRearg[name])) {
|
if (config.rearg && aryKey > 1 && (forceRearg || !mapping.skipRearg[name])) {
|
||||||
result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[aryKey]);
|
result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[aryKey]);
|
||||||
}
|
}
|
||||||
if (config.cap && aryN) {
|
if (config.cap) {
|
||||||
result = iterateeAry(result, aryN);
|
if (reargIndexes) {
|
||||||
|
result = iterateeRearg(result, reargIndexes);
|
||||||
|
} else if (aryN) {
|
||||||
|
result = iterateeAry(result, aryN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (config.curry && aryKey > 1) {
|
if (config.curry && aryKey > 1) {
|
||||||
result = curry(result, aryKey);
|
result = curry(result, aryKey);
|
||||||
|
|||||||
@@ -124,6 +124,11 @@ exports.iterateeAry = {
|
|||||||
'transform': 2
|
'transform': 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Used to map method names to iteratee rearg configs. */
|
||||||
|
exports.iterateeRearg = {
|
||||||
|
'mapKeys': [1]
|
||||||
|
};
|
||||||
|
|
||||||
/** Used to map method names to rearg configs. */
|
/** Used to map method names to rearg configs. */
|
||||||
exports.methodRearg = {
|
exports.methodRearg = {
|
||||||
'assignInWith': [1, 2, 0],
|
'assignInWith': [1, 2, 0],
|
||||||
|
|||||||
@@ -1037,6 +1037,25 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('fp.mapKeys');
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
QUnit.test('should only provide `key` to `iteratee`', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
var args,
|
||||||
|
object = { 'a': 1 };
|
||||||
|
|
||||||
|
var actual = fp.mapKeys(function() {
|
||||||
|
args || (args = slice.call(arguments));
|
||||||
|
}, object);
|
||||||
|
|
||||||
|
assert.deepEqual(args, ['a']);
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('fp.maxBy and fp.minBy');
|
QUnit.module('fp.maxBy and fp.minBy');
|
||||||
|
|
||||||
_.each(['maxBy', 'minBy'], function(methodName) {
|
_.each(['maxBy', 'minBy'], function(methodName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user