There's a revolution calling! Lambda expressions are coming in Java 8 but how can developers benefit? We'll go through a series of code examples, that show how to:
Use the new lambda expressions feature
Write more readable and faster collections processing code using the Streams API
Build complex data processing systems with the new collector abstraction
Use lambda expressions in your own code
32. Putting it Together
for a given an album, find the nationality of every band
playing on that album
33. Putting it Together
1. get all the artists for an album,
2. figure out which artists are bands,
3. find the nationalities of each band
4. put together a list of these values.
34. Putting it Together
Set<String> origins =
album.getMusicians()
.filter(artist -> artist.getName().startsWith("The"))
.map(artist -> artist.getNationality())
.collect(toSet());
35. Eager vs Lazy
Set<String> origins =
album.getMusicians()
.filter(artist -> artist.getName().startsWith("The"))
.map(artist -> artist.getNationality())
// What’s happened at this point?
.collect(toSet());
36. Parallelism
Parallelism no longer means a rewrite of your code
Streams support parallelism out of the box
call .parallelStream() instead of .stream()
Performs well in the right circumstances, but not a
panacea
37. What do you mean simple?
Streams
Collectors
Conclusion
38. Enter the Collector
Collection is mutable reduction
Generic API for building up final values
Already seen collect(toList())
45. Recap of Collectors
Mutable Reduction
A custom collector is just implementing an interface
Can collect other values
min, max
average, sum
summary statistics
join together strings
46. What do you mean simple?
Streams
Collectors
Design Patterns
Conclusion