2015-08-12 06:41:03 +00:00
|
|
|
/* eslint no-shadow:0 */
|
|
|
|
export function curry1(fn) {
|
|
|
|
return function curried(a, b, c) {
|
|
|
|
const n = arguments.length;
|
|
|
|
|
|
|
|
if (n >= 1) return fn(a, b, c);
|
|
|
|
return curried;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function curry2(fn) {
|
|
|
|
return function curried(a, b, c, d) {
|
|
|
|
const n = arguments.length;
|
|
|
|
|
|
|
|
if (n >= 2) return fn(a, b, c, d);
|
|
|
|
if (n === 1) return curry1((b, c, d) => fn(a, b, c, d));
|
|
|
|
return curried;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function curry3(fn) {
|
|
|
|
return function curried(a, b, c, d, e) {
|
|
|
|
const n = arguments.length;
|
|
|
|
|
|
|
|
if (n >= 3) return fn(a, b, c, d, e);
|
|
|
|
if (n === 2) return curry1((c, d, e) => fn(a, b, c, d, e));
|
|
|
|
if (n === 1) return curry2((b, c, d, e) => fn(a, b, c, d, e));
|
|
|
|
return curried;
|
|
|
|
};
|
|
|
|
}
|
2015-08-12 06:53:05 +00:00
|
|
|
|
|
|
|
export function curry4(fn) {
|
|
|
|
return function curried(a, b, c, d, e, f) {
|
|
|
|
const n = arguments.length;
|
|
|
|
|
|
|
|
if (n >= 4) return fn(a, b, c, d, e, f);
|
|
|
|
if (n === 3) return curry1((d, e, f) => fn(a, b, c, d, e, f));
|
|
|
|
if (n === 2) return curry2((c, d, e, f) => fn(a, b, c, d, e, f));
|
|
|
|
if (n === 1) return curry3((b, c, d, e, f) => fn(a, b, c, d, e, f));
|
|
|
|
return curried;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function curry(fn, length = fn.length) {
|
|
|
|
return [
|
|
|
|
fn,
|
|
|
|
curry1,
|
|
|
|
curry2,
|
|
|
|
curry3,
|
|
|
|
curry4,
|
|
|
|
][length](fn);
|
|
|
|
}
|