Add iterateeRearg fp mapping back for mapKeys.

This commit is contained in:
John-David Dalton
2016-02-17 22:11:47 -08:00
parent ab73503859
commit 23768398c5
3 changed files with 45 additions and 5 deletions

View File

@@ -67,6 +67,12 @@ function baseConvert(util, name, func, options) {
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) {
return n == 2
? function(a, b) { return func(a, b); }
@@ -107,9 +113,14 @@ function baseConvert(util, name, func, options) {
var iterateeAry = function(func, n) {
return overArg(func, function(func) {
return typeof func == 'function'
? baseAry(func, n)
: func;
return typeof func == 'function' ? 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) {
if (name == otherName) {
var aryN = !isLib && mapping.iterateeAry[name],
reargIndexes = mapping.iterateeRearg[name],
spreadStart = mapping.methodSpread[name];
result = wrapped;
@@ -223,8 +235,12 @@ function baseConvert(util, name, func, options) {
if (config.rearg && aryKey > 1 && (forceRearg || !mapping.skipRearg[name])) {
result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[aryKey]);
}
if (config.cap && aryN) {
result = iterateeAry(result, aryN);
if (config.cap) {
if (reargIndexes) {
result = iterateeRearg(result, reargIndexes);
} else if (aryN) {
result = iterateeAry(result, aryN);
}
}
if (config.curry && aryKey > 1) {
result = curry(result, aryKey);

View File

@@ -124,6 +124,11 @@ exports.iterateeAry = {
'transform': 2
};
/** Used to map method names to iteratee rearg configs. */
exports.iterateeRearg = {
'mapKeys': [1]
};
/** Used to map method names to rearg configs. */
exports.methodRearg = {
'assignInWith': [1, 2, 0],

View File

@@ -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');
_.each(['maxBy', 'minBy'], function(methodName) {