While typing the example to ask the question, I found the answer:
Stream::reduce()
returns an Optional
which has a method: orElse()
. So,
System.out.println("Sum = " + values.stream().reduce((x, y) -> x.add(y)).get());
becomes
System.out.println("Sum = " + values.stream().reduce((x, y) -> x.add(y)).orElse(BigDecimal.ZERO));
So I decided to post a Q-and-A.
Lambdas are great. +1 Java.