Fix coercing arity in baseCurry.

This commit is contained in:
John-David Dalton
2014-08-02 22:08:17 -07:00
parent ea219f683e
commit c3cd94b695
2 changed files with 17 additions and 2 deletions

View File

@@ -1624,7 +1624,7 @@
*/
function baseCurry(func, bitmask, arity) {
if (typeof arity != 'number') {
arity = +arity || (func ? func.length : 0);
arity = arity == null ? (func ? func.length : 0) : (+arity || 0);
}
return createWrapper([func, bitmask, arity]);
}

View File

@@ -2229,7 +2229,7 @@
deepEqual(curried(1, 2, 3, 4), expected);
});
test('should allow specifying `arity`', 3, function(){
test('should allow specifying `arity`', 3, function() {
var curried = _.curry(fn, 3),
expected = [1, 2, 3];
@@ -2238,6 +2238,21 @@
deepEqual(curried(1, 2, 3), expected);
});
test('should coerce `arity` to a number', 2, function() {
var values = ['0', 'xyz'],
expected = _.map(values, _.constant([]));
var actual = _.map(values, function(arity) {
var curried = _.curry(fn, arity);
return curried();
});
deepEqual(actual, expected);
curried = _.curry(fn, '2');
deepEqual(curried(1)(2), [1, 2]);
});
test('should work with partialed methods', 2, function() {
var curried = _.curry(fn),
expected = [1, 2, 3, 4];