An Introduction To Functional Programming

With

Lodash

λ

What is currying?

More than just a tasty dish.

Haskell Brooks Curry

Normal Curry

From Wikipedia:

 Translating the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single argument.*

  • Breaking a function down into multiple “partials”, one for each argument.

  • These partials can then be evaluated individually until all arguments have been supplied, at which point the result is obtained.

Example

function add(a, b) {
  return a + b;
}

add(1, 2);
// => 3
function add(a) {
  return function(b) {
    return a + b;
  }
}

add(1)
// => [Function] function(b) { return 1 + b }

add(1)(2)
// => 3

deck

By unicode

deck

  • 141