Skip to content

Instantly share code, notes, and snippets.

@kedashoe
Last active August 29, 2015 14:15
Show Gist options
  • Save kedashoe/e0184a5b91e63084299b to your computer and use it in GitHub Desktop.
Save kedashoe/e0184a5b91e63084299b to your computer and use it in GitHub Desktop.
curry with placeholders curry2 and curry3
function curry2(fn) {
return function(a, b) {
switch (arguments.length) {
case 1:
return function(B) {
return fn(a, B);
};
default:
if (a === __) {
return function(A) {
return fn(A, b);
};
}
return fn(a, b);
}
};
}
function curry3(fn) {
return function(a, b, c) {
switch (arguments.length) {
case 1:
return curry2(function(B, C) {
return fn(a, B, C);
});
case 2:
if (a === __) {
return curry2(function(A, C) {
return fn(A, b, C);
});
}
return function(C) {
return fn(a, b, C);
};
default:
if (a === __ && b === __) {
return curry2(function(A, B) {
return fn(A, B, c);
});
}
else if (a === __) {
return function(A) {
return fn(A, b, c);
};
}
else if (b === __) {
return function(B) {
return fn(a, B, c);
};
}
return fn(a, b, c);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment