Lambdas, streams and Optional
Functional Java: the lambda syntax and the functional interface it fits, Function, Consumer, Supplier and Predicate, and the method references that replace them. Streams follow, from map and filter to collect, with the terminal operations, the collectors and the numeric streams, then flatMap, distinct and takeWhile. Optional gets a lesson and a second one on its traps, parallel streams are measured against a sequential one, and streams are set against the loops they replace. The part ends with a sales report capstone and composing functions with andThen and compose.
7.1
Lambdas
the syntax, a functional interface, effectively final captures, a lambda as an argument
Open
7.2
The functional interfaces
Function, Consumer, Supplier, Predicate, BiFunction, UnaryOperator
Open
7.3
Method references
:: static, bound, unbound and constructor references, a chain of them
Open
7.4
Streams
stream(), map, filter, collect, a pipeline against the same loop
Open
7.5
Terminal operations
count, findFirst, anyMatch, allMatch, reduce, forEach
Open
7.6
Collectors
toList, toSet, joining, groupingBy, partitioningBy, counting
Open
7.7
Numeric streams
IntStream.range, sum, average, summaryStatistics, boxed
Open
7.8
Optional
of, ofNullable, empty, map, orElse, ifPresent, orElseThrow
Open
7.9
flatMap and the rest
flatMap, distinct, sorted, limit, skip, takeWhile
Open
7.10
Parallel streams
parallelStream, a measured comparison, when it pays and when it does not
Open
7.11
Streams against loops
side effects, a stream reused, a checked exception inside a lambda, readability
Open
7.12
Capstone: a sales report
records, a stream pipeline, groupingBy, a formatted table
Open
7.13
Optional in practice
a field of Optional, get() without a check, orElse against orElseGet
Open
7.14
Composing functions
andThen, compose, a predicate chain, a small pipeline built from parts
Open