Sitemap
Heap & Wire

Deep dives into Java, Spring and modern backend architecture

Member-only story

Currying and Partial Application in Java: It Works. That’s Exactly Why You Probably Shouldn’t

--

Press enter or click to view image in full size
Currying and Partial Application — Java

There is a particular kind of Java code that makes everyone in the code review go silent.

It starts innocently:

Function<Integer,
Function<Integer,
Function<Integer, Integer>>> add =
a -> b -> c -> a + b + c;

Then somebody proudly says:

“Look. Currying.”

And technically, they are correct.

Java can do currying.

Java can also do partial application.

Java can compose functions.

Java can make higher-order functions.

The more interesting question is not whether Java can do it.

It is:

When does currying actually make Java code better?

Because the answer is surprisingly uncomfortable.

In a language designed around ordinary methods, nominal types, overloaded functions, object-oriented APIs, and a type system without first-class function syntax, currying often creates more ceremony than leverage.

The underlying functional idea is excellent.

--

--