Function Composition

 
symbols.map(StockUtil::getPrice)
 
.filter(StockUtil.isPriceLessThan(500))
 
.reduce(StockUtil::pickHigh)
 
.get();

We can compose functions to transform objects through a series of operations like in this example. In the functional style of programming, function composition or chaining is a very powerful construct to implement associative operations.

Get Functional Programming in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.