Java Functional Programming



Operations: 
Intermediate(transform a stream to another):
  • Map
  • flatMap 
  • Filter
  • Collect
  • forEach 
  • Reduce
  • Sorted
  • peek
  • limit 
  • skip 
Terminal operation:
  • forEach
  • Terminal
  • count
  • reduce
  • collect
  • anyMatch
  • allMatch
  • noneMatch
  • findFirst
  • findAny
  • min
  • max
  • toArray
More details:
There are two ways to achieve Function composition. They are compose and andThen.
Function<Integer, Integer> sum = x -> x + x; 
Function<Integer, Integer> square = y -> y * y;  
Integer sumAndSquareResult = sum.compose(square).apply(3); // Returns 18
Integer squareAndSumResult = sum.andThen(square).apply(3); // Returns 36