Composing Software
Eric Elliott


Notes

Currying

Currying is “the technique of converting a function that takes multiple arguments into a sequence of functions that each take a single argument.”

Without currying:

const add = (a, b) => a + b
add(2, 3) // return 5

With currying:

const add = a => b =>  a + b
add(2)(3) // returns 5

Specialization and Generalization


There are two important parts of abstraction:

  • Generalization The process of extracting only the shared properties and behaviors that serve the general use case
  • Specialization The process of providing the implementation details required to serve the special case

Currying is probably used to specialize and generalize functions. From the above example, we can specialize the generic adding functionlity to make increment function by only 1.

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