Skip to Content
Functional Programming in Java
book

Functional Programming in Java

by Venkat Subramaniam
February 2014
Intermediate to advanced
160 pages
4h 59m
English
Pragmatic Bookshelf
Content preview from Functional Programming in Java

Reusing Lambda Expressions

Lambda expressions are deceivingly concise and it’s easy to carelessly duplicate them in code. Duplicate code leads to poor-quality code that’s hard to maintain; if we needed to make a change, we’d have to find and touch the relevant code in several places.

Avoiding duplication can also help improve performance. By keeping the code related to a piece of knowledge concentrated in one place, we can easily study its performance profile and make changes in one place to get better performance.

Now let’s see how easy it is to fall into the duplication trap when using lambda expressions, and consider ways to avoid it.

Suppose we have a few collections of names: friends, editors, comrades, and so on.

 
final​ ​List​<​String ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Functional Programming in Java

Functional Programming in Java

Pierre-Yves Saumont

Publisher Resources

ISBN: 9781941222690Errata Page