Currying

Function currying is a functional design process. A function that takes multiple arguments are refactored into a function that takes a single argument. For example:

1
2
3
4
5
function add(a, b, c) {
  return a + b + c;
}

add(1, 2, 3); // equals 6

becomes:

1
2
3
4
5
6
7
function add(a) {
  return function(b) {
    return a + b;
  }
}

add(add(1)(2))(3) // equals 6

Further Reading