Use the following problems to test your functional style programming prowess. I strongly encourage you to give each problem a try before you turn to the solutions and download the example programs:
- Testing high-order functions: Write several unit tests for testing so-called high-order functions.
- Testing methods that use lambdas: Write several unit tests for testing methods that use lambdas.
- Debugging lambdas: Provide a technique for debugging lambdas.
- Filtering the non-zero elements of a stream: Write a stream pipeline that filters the non-zero elements of a stream.
- Infinite streams, takeWhile(), and dropWhile(): Write several snippets of code that work with infinite streams. In addition, write several examples of working with the takeWhile() and dropWhile() APIs.
- Mapping a stream: Write several examples of mapping a stream via map() and flatMap().
- Finding different elements in a stream: Write a program for finding different elements in a stream.
- Matching different elements in a stream: Write a program for matching different elements in a stream.
- Sum, max, and min in a stream: Write a program for computing the sum, max, and min of the given stream via primitive specializations of Stream and Stream.reduce().
- Collecting the results of a stream: Write several snippets of code for collecting the results of a stream in a list, map, and set.
- Joining the results of a stream: Write several snippets of code for joining the results of a stream into a String.
- Summarization collectors: Write several snippets of code to reveal the usage of summarization collectors.
- Grouping: Write snippets of code for working with groupingBy() collectors.
- Partitioning: Write several snippets of code for working with partitioningBy() collectors.
- Filtering, flattening, and mapping collectors: Write several snippets of code for exemplifying the usage of filtering, flattening, and mapping collectors.
- Teeing: Write several examples that merge the results of two collectors (JDK 12 and Collectors.teeing()).
- Writing a custom collector: Write a program that represents a custom collector.
- Method reference: Write an example of method reference.
- Parallel processing of streams: Provide a brief overview of the parallel processing of streams. Provide at least one example each for parallelStream(), parallel(), and spliterator().
- Null-safe streams: Write a program that returns a null-safe stream from an element or a collection of elements.
- Composing functions, predicates, and comparators: Write several examples for composing functions, predicates, and comparators.
- Default methods: Write an interface that contains a default method.