diff --git a/fp/_baseConvert.js b/fp/_baseConvert.js index ea2ed2e97..d294820d8 100644 --- a/fp/_baseConvert.js +++ b/fp/_baseConvert.js @@ -209,6 +209,12 @@ function baseConvert(util, name, func, options) { return func; }; }, + 'rearg': function(rearg) { + return function(func, indexes) { + var n = indexes ? indexes.length : 0; + return curry(rearg(func, indexes), n); + }; + }, 'runInContext': function(runInContext) { return function(context) { return baseConvert(util, runInContext(context), options); diff --git a/fp/_mapping.js b/fp/_mapping.js index bd1c9d4fa..b8727eeeb 100644 --- a/fp/_mapping.js +++ b/fp/_mapping.js @@ -321,6 +321,7 @@ exports.skipFixed = { 'flowRight': true, 'iteratee': true, 'mixin': true, + 'rearg': true, 'runInContext': true }; diff --git a/test/test-fp.js b/test/test-fp.js index 20895bebb..cade9cc09 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -1779,6 +1779,30 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('fp.rearg'); + + (function() { + function fn(a, b, c) { + return [a, b, c]; + } + + QUnit.test('should be curried', function(assert) { + assert.expect(1); + + var rearged = fp.rearg([1, 2, 0])(fn); + assert.deepEqual(rearged('c', 'a', 'b'), ['a', 'b', 'c']); + }); + + QUnit.test('should curry the rearged function', function(assert) { + assert.expect(1); + + var rearged = fp.rearg([1, 2, 0], fn); + assert.deepEqual(rearged('c')('a')('b'), ['a', 'b', 'c']); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('reduce methods'); _.each(['reduce', 'reduceRight'], function(methodName) {