Is there a way I can terminate a Stream (apart from .limit(long)
).
What I'm really looking for is a kind of .until(Predicate<T>)
. Method filter
is obviously not usable here.
Example:
Stream.iterate(service.first(), service::next)
.until(item -> item.isTerminator())
This example might not make sense, but shows the concept I'm looking for.
Is it even possible to do something like that?