liveBook · Manning

Currying

As explained in Functional Programming in Scala, Second Edition

Currying is the transformation of a function taking multiple arguments into a sequence of functions each taking one argument.

Currying transforms a function with two arguments into a function that takes one argument and returns another function. The type A => (B => C) reads as: supply an A, then receive a function from B to C. section 2.5

Partial application

Given an A and a function requiring both A and B to produce C, partial application fixes the A and returns a function waiting only for B: def partial1[A, B, C](a: A, f: (A, B) => C): B => C = (b: B) => f(a, b). Currying generalizes this pattern by transforming the original two-argument function itself. section 2.5

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Explains the type shape and relates it to partial application, while leaving implementation as an exercise.
Examples
Uses a two-argument Scala function, a partially applied function, and a carrot-for-apple-and-banana analogy.
What you can do after
Practice implementing curry and uncurry from their Scala type signatures.
How it connects
Connects currying with partial application, uncurry, higher-order functions, and function composition.

Also explained in

Compare how 7 books explain currying →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in Scala, Second Edition. The section links point to the parts of the book it draws on.