List of Figures

Chapter 1. Java 8: why should you care?

Figure 1.1. Programming languages ecosystem and climate change

Figure 1.2. Unix commands operating on streams

Figure 1.3. Passing method compareUsingCustomerId as an argument to sort

Figure 1.4. Passing the method reference File::isHidden to the method listFiles

Figure 1.5. A possible problem with two threads trying to add to a shared sum variable. The result is 105 instead of an expected result of 108.

Figure 1.6. Forking filter onto two CPUs and joining the result

Chapter 2. Passing code with behavior parameterization

Figure 2.1. Different strategies for selecting an Apple

Figure 2.2. Parameterizing the behavior of filterApples and passing different filter strategies

Figure 2.3. Parameterizing the behavior of filterApples and passing different filter strategies

Figure 2.4. Behavior parameterization vs. value parameterization

Chapter 3. Lambda expressions

Figure 3.1. A lambda expression is composed of parameters, an arrow, and a body.

Figure 3.2. Tasks A and B are surrounded by the same redundant code responsible for preparation/cleanup.

Figure 3.3. Four-step process to apply the execute around pattern

Figure 3.4. Deconstructing the type-checking process of a lambda expression

Figure 3.5. Recipes for constructing method references for three different types of lambda expressions

Figure 3.6. Using andThen vs. compose

Figure 3.7. A transformation pipeline using andThen

Figure 3.8. Area under the function f(x) = x + 10 for x from 3 to 7

Chapter 4. Introducing streams

Figure 4.1. Chaining stream operations forming a stream pipeline

Figure 4.2. Filtering a menu using a stream to find out three high-calorie dish names

Figure 4.3. Streams vs. collections

Figure 4.4. Internal vs. external iteration

Figure 4.5. Intermediate vs. terminal operations

Chapter 5. Working with streams

Figure 5.1. Filtering a stream with a predicate

Figure 5.2. Filtering unique elements in a stream

Figure 5.3. Truncating a stream

Figure 5.4. Skipping elements in a stream

Figure 5.5. Incorrect use of map to find unique characters from a list of words

Figure 5.6. Using flatMap to find the unique characters from a list of words

Figure 5.7. Using reduce to sum the numbers in a stream

Figure 5.8. A reduce operation—calculating the maximum

Figure 5.9. The Pythagorean theorem

Chapter 6. Collecting data with streams

Figure 6.1. The reduction process grouping the transactions by currency

Figure 6.2. The aggregation process of the summingInt collector

Figure 6.3. The reduction process calculating the total number of calories in the menu

Figure 6.4. Classification of an item in the stream during the grouping process

Figure 6.5. Equivalence between n-level nested map and n-dimensional classification table

Figure 6.6. Combining the effect of multiple collectors by nesting one inside the other

Figure 6.7. Logical steps of the sequential reduction process

Figure 6.8. Parallelizing the reduction process using the combiner method

Chapter 7. Parallel data processing and performance

Figure 7.1. A parallel reduction operation

Figure 7.2. iterate is inherently sequential.

Figure 7.3. The fork/join process

Figure 7.4. The fork/join algorithm

Figure 7.5. The work-stealing algorithm used by the fork/join framework

Figure 7.6. The recursive splitting process

Figure 7.7. The state transitions of the WordCounter when a new Character c is traversed

Chapter 8. Refactoring, testing, and debugging

Figure 8.1. The strategy design pattern

Figure 8.2. The observer design pattern

Figure 8.3. The chain of responsibility design pattern

Figure 8.4. Examining values flowing in a stream pipeline with peek

Chapter 9. Default methods

Figure 9.1. Adding a method to an interface

Figure 9.2. Evolving an API by adding a method to Resizable. Recompiling the application produces errors because it depends on the Resizable interface.

Figure 9.3. Single inheritance vs. multiple inheritance

Figure 9.4. Multiple behavior composition

Figure 9.5. The most specific default-providing interface wins.

Figure 9.6. Inheriting from a class and implementing two interfaces

Figure 9.7. Implementing two interfaces

Figure 9.8. The diamond problem

Chapter 10. Using Optional as a better alternative to null

Figure 10.1. An optional Car

Figure 10.2. Comparing the map methods of Streams and Optionals

Figure 10.3. A two-level optional

Figure 10.4. Comparing the flatMap methods of Stream and Optional

Figure 10.5. The Person/Car/Insurance dereferencing chain using optionals

Chapter 11. CompletableFuture: composable asynchronous programming

Figure 11.1. A typical mash-up application

Figure 11.2. Concurrency vs. parallelism

Figure 11.3. Using a Future to execute a long operation asynchronously

Figure 11.4. Why Stream's laziness causes a sequential computation and how to avoid it

Figure 11.5. Composing synchronous operations and asynchronous tasks

Figure 11.6. Combining two independent asynchronous tasks

Chapter 12. New Date and Time API

Figure 12.1. Making sense of a ZonedDateTime

Chapter 13. Thinking functionally

Figure 13.1. A mutable shared across multiple classes. It’s difficult to understand who the owner is.

Figure 13.2. A function with side effects

Figure 13.3. A function with no side effects

Figure 13.4. A function throwing an exception

Figure 13.5. Recursive definition of factorial, which requires several stack frames

Figure 13.6. Tail-recursive definition of factorial, which can reuse a single stack frame

Chapter 14. Functional programming techniques

Figure 14.1. comparing takes a function as parameter and returns another function.

Figure 14.2. The data structure is destructively updated.

Figure 14.3. Functional style, no modifications to the data structure

Figure 14.4. No existing data structure was harmed during the making of this update to the Tree.

Figure 14.5. Elements of a LinkedList exist (are spread out) in memory. But elements of a LazyList are created on demand by a Function—you can see them as spread out in time.

Chapter 15. Blending OOP and FP: comparing Java 8 and Scala

Figure 15.1. Stream-like operations with Scala’s List

Chapter 16. Conclusions and where next for Java

Figure 16.1. Objects vs. value types

Appendix C. Performing multiple operations in parallel on a stream

Figure C.1. The StreamForker in action

Figure C.2. The StreamForker building blocks

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset