T
- traversed item type@FunctionalInterface public interface Traverser<T>
null
items. Each
invocation of next()
consumes and returns the next item in the
sequence if available, or null
if not. If the traverser is
null-terminated, getting a null
means it's exhausted and
will keep returning null
forever.
All transformation methods (map()
, append()
, peek()
,
...) are allowed to either return a new instance or to modify this
instance. For correct functionality, you must always use the returned value
and stop using the original instance.
Modifier and Type | Method and Description |
---|---|
default Traverser<T> |
append(T item)
Returns a traverser that will return all the items of this traverser,
plus an additional item once this one returns
null . |
default Traverser<T> |
dropWhile(Predicate<? super T> predicate)
Returns a traverser that will emit a suffix of the original traverser,
starting from the item for which the predicate fails (inclusive).
|
default Traverser<T> |
filter(Predicate<? super T> filterFn)
Returns a traverser that will emit the same items as this traverser, but
only those that pass the given predicate.
|
default <R> Traverser<R> |
flatMap(Function<? super T,? extends Traverser<R>> flatMapFn)
Returns a traverser that will apply the given mapping function to each
item retrieved from this traverser and emit all the items from the
resulting traversers, which must be null-terminated.
|
default <R> Traverser<R> |
map(Function<? super T,? extends R> mapFn)
Returns a traverser that will emit the results of applying
mapFn to this traverser's items. |
T |
next()
Returns the next item, removing it from this traverser.
|
default Traverser<T> |
onFirstNull(Runnable action)
Returns a traverser that will emit the same items as this traverser and
additionally run the supplied action the first time this traverser
returns
null . |
default Traverser<T> |
peek(Consumer<? super T> action)
Returns a traverser that will emit the same items as this traverser,
additionally passing each (non-null) item to the supplied consumer.
|
default Traverser<T> |
prepend(T item)
Returns a traverser which prepends an additional item in front of
all the items of this traverser.
|
default Traverser<T> |
takeWhile(Predicate<? super T> predicate)
Returns a traverser that will emit a prefix of the original traverser,
up to the item for which the predicate fails (exclusive).
|
T next()
null
. If this traverser is null-terminated,
getting a null
means it's exhausted and will keep returning
null
forever. Otherwise, trying again later may produce one.@Nonnull @CheckReturnValue default <R> Traverser<R> map(@Nonnull Function<? super T,? extends R> mapFn)
mapFn
to this traverser's items. If mapFn
returns null
for an item, the returned traverser drops it and immediately moves on to
the next item from this traverser. This way mapFn
can perform
filtering in addition to transformation.@Nonnull @CheckReturnValue default Traverser<T> filter(@Nonnull Predicate<? super T> filterFn)
@Nonnull @CheckReturnValue default <R> Traverser<R> flatMap(@Nonnull Function<? super T,? extends Traverser<R>> flatMapFn)
The function must not return null traverser, but can return an empty traverser.
@Nonnull @CheckReturnValue default Traverser<T> takeWhile(@Nonnull Predicate<? super T> predicate)
@Nonnull @CheckReturnValue default Traverser<T> dropWhile(@Nonnull Predicate<? super T> predicate)
@Nonnull @CheckReturnValue default Traverser<T> append(@Nonnull T item)
null
. After that
it continues forwarding the return values of this traverser. It is
meant to be used on finite traversers.
Default implementations always returns a new traverser instance. If you
need to append multiple objects or use this method frequently,
AppendableTraverser
might be a better choice.
@Nonnull @CheckReturnValue default Traverser<T> prepend(@Nonnull T item)
@Nonnull @CheckReturnValue default Traverser<T> peek(@Nonnull Consumer<? super T> action)
Copyright © 2021 Hazelcast, Inc.. All rights reserved.