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 it is available, or returns null
if not. An item may
still become available later on.
An important special case is traversing a finite sequence. In this case the
null
return value means "the sequence is exhausted" and all future
next()
calls will return null
.
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(java.util.function.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(java.util.function.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(java.util.function.Function<? super T,? extends Traverser<? extends R>> mapFn)
Returns a traverser traverser that will apply the given mapping function
to each item retrieved from this traverser and emit all the items from
the resulting traverser(s).
|
default <R> Traverser<R> |
map(java.util.function.Function<? super T,? extends R> mapFn)
Returns a traverser traverser that will emit the results of applying the
mapping function to this traverser's items.
|
T |
next()
Returns the next item in the sequence, or
null if there is no next
item to return. |
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(java.util.function.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(java.util.function.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 there is no next
item to return. If this traverser represents a finite sequence, it will
keep returning null
once exhausted. If it represents an infinite
sequence, null
only means "there is currently no next item", but
trying again later may produce one.@Nonnull default <R> Traverser<R> map(@Nonnull java.util.function.Function<? super T,? extends R> mapFn)
@Nonnull default Traverser<T> filter(@Nonnull java.util.function.Predicate<? super T> filterFn)
@Nonnull default Traverser<T> takeWhile(@Nonnull java.util.function.Predicate<? super T> pred)
@Nonnull default Traverser<T> dropWhile(@Nonnull java.util.function.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.@Nonnull default Traverser<T> prepend(@Nonnull T item)
@Nonnull default <R> Traverser<R> flatMap(@Nonnull java.util.function.Function<? super T,? extends Traverser<? extends R>> mapFn)
@Nonnull default Traverser<T> peek(@Nonnull java.util.function.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 © 2017 Hazelcast, Inc.. All Rights Reserved.