Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: curryN utilize optimized _curry1, _curry2, _curry3 #3461

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions source/curryN.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _arity from './internal/_arity.js';
import _curry1 from './internal/_curry1.js';
import _curry2 from './internal/_curry2.js';
import _curry3 from './internal/_curry3.js';
import _curryN from './internal/_curryN.js';


Expand Down Expand Up @@ -47,9 +48,9 @@ import _curryN from './internal/_curryN.js';
* g(4); //=> 10
*/
var curryN = _curry2(function curryN(length, fn) {
if (length === 1) {
return _curry1(fn);
}
if (length === 1) {return _curry1(fn);}
if (length === 2) {return _curry2(fn);}
if (length === 3) {return _curry3(fn);}
return _arity(length, _curryN(length, [], fn));
});
export default curryN;
8 changes: 4 additions & 4 deletions source/internal/_curry2.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export default function _curry2(fn) {
case 1:
return _isPlaceholder(a)
? f2
: _curry1(function(_b) { return fn(a, _b); });
: _curry1(function(_b) { return fn.call(this, a, _b); });
default:
return _isPlaceholder(a) && _isPlaceholder(b)
? f2
: _isPlaceholder(a)
? _curry1(function(_a) { return fn(_a, b); })
? _curry1(function(_a) { return fn.call(this, _a, b); })
: _isPlaceholder(b)
? _curry1(function(_b) { return fn(a, _b); })
: fn(a, b);
? _curry1(function(_b) { return fn.call(this, a, _b); })
: fn.call(this, a, b);
}
};
}
22 changes: 11 additions & 11 deletions source/internal/_curry3.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ export default function _curry3(fn) {
case 1:
return _isPlaceholder(a)
? f3
: _curry2(function(_b, _c) { return fn(a, _b, _c); });
: _curry2(function(_b, _c) { return fn.call(this, a, _b, _c); });
case 2:
return _isPlaceholder(a) && _isPlaceholder(b)
? f3
: _isPlaceholder(a)
? _curry2(function(_a, _c) { return fn(_a, b, _c); })
? _curry2(function(_a, _c) { return fn.call(this, _a, b, _c); })
: _isPlaceholder(b)
? _curry2(function(_b, _c) { return fn(a, _b, _c); })
: _curry1(function(_c) { return fn(a, b, _c); });
? _curry2(function(_b, _c) { return fn.call(this, a, _b, _c); })
: _curry1(function(_c) { return fn.call(this, a, b, _c); });
default:
return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c)
? f3
: _isPlaceholder(a) && _isPlaceholder(b)
? _curry2(function(_a, _b) { return fn(_a, _b, c); })
? _curry2(function(_a, _b) { return fn.call(this, _a, _b, c); })
: _isPlaceholder(a) && _isPlaceholder(c)
? _curry2(function(_a, _c) { return fn(_a, b, _c); })
? _curry2(function(_a, _c) { return fn.call(this, _a, b, _c); })
: _isPlaceholder(b) && _isPlaceholder(c)
? _curry2(function(_b, _c) { return fn(a, _b, _c); })
? _curry2(function(_b, _c) { return fn.call(this, a, _b, _c); })
: _isPlaceholder(a)
? _curry1(function(_a) { return fn(_a, b, c); })
? _curry1(function(_a) { return fn.call(this, _a, b, c); })
: _isPlaceholder(b)
? _curry1(function(_b) { return fn(a, _b, c); })
? _curry1(function(_b) { return fn.call(this, a, _b, c); })
: _isPlaceholder(c)
? _curry1(function(_c) { return fn(a, b, _c); })
: fn(a, b, c);
? _curry1(function(_c) { return fn.call(this, a, b, _c); })
: fn.call(this, a, b, c);
}
};
}