parent
dea78333ff
commit
932da9f7d5
@ -13,7 +13,7 @@ function countArguments(args, max) {
|
||||
}
|
||||
|
||||
export function curry1(fn) {
|
||||
return function curried(a, b, c) {
|
||||
return function curried(a, ...[b, c]) {
|
||||
const n = countArguments(arguments);
|
||||
|
||||
if (n >= 1) return fn(a, b, c);
|
||||
@ -22,7 +22,7 @@ export function curry1(fn) {
|
||||
}
|
||||
|
||||
export function curry2(fn) {
|
||||
return function curried(a, b, c, d) {
|
||||
return function curried(a, b, ...[c, d]) {
|
||||
const n = countArguments(arguments, 2);
|
||||
|
||||
if (b === _ || c === _ || d === _) {
|
||||
@ -40,7 +40,7 @@ export function curry2(fn) {
|
||||
}
|
||||
|
||||
export function curry3(fn) {
|
||||
return function curried(a, b, c, d, e) {
|
||||
return function curried(a, b, c, ...[d, e]) {
|
||||
const n = countArguments(arguments, 3);
|
||||
|
||||
if (c === _ || d === _ || e === _) {
|
||||
@ -68,7 +68,7 @@ export function curry3(fn) {
|
||||
}
|
||||
|
||||
export function curry4(fn) {
|
||||
return function curried(a, b, c, d, e, f) {
|
||||
return function curried(a, b, c, d, ...[e, f]) {
|
||||
const n = countArguments(arguments, 4);
|
||||
|
||||
if (d === _ || e === _ || f === _) {
|
||||
|
@ -12,6 +12,11 @@ describe('curry1', () => {
|
||||
const curried = curry1((a, b, c) => [a, b, c]);
|
||||
expect(curried(1, 2, 3, 4)).to.eql([1, 2, 3]);
|
||||
});
|
||||
|
||||
it('returns a fn with arity of 1', () => {
|
||||
const curried = curry1((a, b, c) => [a, b, c]);
|
||||
expect(curried).to.have.length(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('curry2', () => {
|
||||
@ -31,6 +36,11 @@ describe('curry2', () => {
|
||||
const curried = curry2((a, b, c, d) => [a, b, c, d]);
|
||||
expect(curried(_, 2)(1, 3, 4)).to.eql([1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
it('returns a fn with arity of 2', () => {
|
||||
const curried = curry2((a, b, c, d) => [a, b, c, d]);
|
||||
expect(curried).to.have.length(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('curry3', () => {
|
||||
@ -53,6 +63,11 @@ describe('curry3', () => {
|
||||
expect(curried(_, 2, 3)('c', 4, 5)).to.eql(['c', 2, 3, 4, 5]);
|
||||
expect(curried(_, _, 3)('d', 2, 4, 5)).to.eql(['d', 2, 3, 4, 5]);
|
||||
});
|
||||
|
||||
it('returns a fn with arity of 3', () => {
|
||||
const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]);
|
||||
expect(curried).to.have.length(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('curry4', () => {
|
||||
@ -87,4 +102,9 @@ describe('curry4', () => {
|
||||
|
||||
expect(curried(_, _, _, 4)('k', 2, 3, 5, 6)).to.eql(['k', 2, 3, 4, 5, 6]);
|
||||
});
|
||||
|
||||
it('returns a fn with arity of 4', () => {
|
||||
const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]);
|
||||
expect(curried).to.have.length(4);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user