In the javaodoc for the stream package, at the end of the section Parallelism
, I read:
Most stream operations accept parameters that des
Examples of stateful stream lambdas:
collect(Collector)
: The Collector
is by definition stateful, since it has to collect all the elements in a collection (state).forEach(Consumer)
: The Consumer
is by definition stateful, well except if it's a black hole (no-op).peek(Consumer)
: The Consumer
is by definition stateful, because why peek if not to store it somewhere (e.g. log).So, Collector
and Consumer
are two lambda interfaces that by definition are stateful.
All the others, e.g. Predicate
, Function
, UnaryOperator
, BinaryOperator
, and Comparator
, should be stateless.