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.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> pred)
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<? extends 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 . |
static <T> Traverser<T> |
over(T... items)
Returns a traverser over the supplied arguments (or item array).
|
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> pred)
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 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 default Traverser<T> filter(@Nonnull Predicate<? super T> filterFn)
@Nonnull default <R> Traverser<R> flatMap(@Nonnull Function<? super T,? extends Traverser<? extends R>> flatMapFn)
@Nonnull default Traverser<T> takeWhile(@Nonnull Predicate<? super T> pred)
@Nonnull default Traverser<T> dropWhile(@Nonnull Predicate<? super T> pred)
@Nonnull 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 default Traverser<T> prepend(@Nonnull T item)
@Nonnull default Traverser<T> peek(@Nonnull Consumer<? super T> action)
@Nonnull default Traverser<T> onFirstNull(@Nonnull Runnable action)
null
.@SafeVarargs static <T> Traverser<T> over(T... items)
T
- type of the itemsitems
- the items to traverse overCopyright © 2018 Hazelcast, Inc.. All rights reserved.