Returns a stream consisting of elements of this stream where every series
of elements matched the predicate is replaced with first element from the
series.
This is a quasi-intermediate
partial reduction operation.
This operation is equivalent to
collapse(collapsible, MoreCollectors.first()).map(Optional::get), but more efficient.
Note that this operation always tests the adjacent pairs of input
elements. In some scenarios it's desired to test every element with the
first element of the current series. In this case consider using
MoreCollectors#dominators(BiPredicate) collector instead.
For sorted stream
collapse(Objects::equals) is equivalent to
distinct().