Skip to content

Instantly share code, notes, and snippets.

@jamischarles jamischarles/curry.js
Last active Sep 24, 2015

What would you like to do?
A simple example of currying in JS
// This is a 'curried' function. If it receives less params than it expects, it returns a function which expects the rest of the params.
function add(a, b) {
// if 2nd param wasn't passed, return a function that holds the 1st param via closure, but expects another param.
if (typeof b === "undefined") {
return function(c) {
a + c;
// if 2 params are passed return the result
return a + b;
// 4
// we are now using the curried function
// 3
// and we can do this...
var add2 = add(2);
// 5
// some more reading here:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.