Spliterator is not only about parallelism
Many are still mistaken about the purpose of Spliterator
.
It is not only about parallelism.
Spliterator
is the core traversing mechanism of Java Streams,
regardless of being processed in parallel or sequentially.
Whenever you build a Stream
from an Iterator
you are wrapping
it around a Spliterator
and incurring in useless indirections.
Remember the answer stated by Bryan Goetz (author of Java streams)
to the question of Miguel Gamboa about the choice between Iterator
or Stream
regarding laziness in a domain model design, namely:
- “
Spliterator
has fundamentally lower per-element access costs than _Iterator, even sequentially._”- ” The Iterator protocol is fundamentally less efficient.”
- “
Spliterator
further offers a “fast-path” iteration”