Package com.hazelcast.jet
Interface Traverser<T>
- Type Parameters:
T
- traversed item type
- All Known Implementing Classes:
AppendableTraverser
,ResettableSingletonTraverser
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Traverses a potentially infinite sequence of non-
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.
- Since:
- Jet 3.0
-
Method Summary
Modifier and TypeMethodDescriptionReturns a traverser that will return all the items of this traverser, plus an additional item once this one returnsnull
.Returns a traverser that will emit a suffix of the original traverser, starting from the item for which the predicate fails (inclusive).Returns a traverser that will emit the same items as this traverser, but only those that pass the given predicate.default <R> Traverser<R>
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>
Returns a traverser that will emit the results of applyingmapFn
to this traverser's items.next()
Returns the next item, removing it from this traverser.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 returnsnull
.Returns a traverser that will emit the same items as this traverser, additionally passing each (non-null) item to the supplied consumer.Returns a traverser which prepends an additional item in front of all the items of this traverser.Returns a traverser that will emit a prefix of the original traverser, up to the item for which the predicate fails (exclusive).
-
Method Details
-
next
T next()Returns the next item, removing it from this traverser. If no item is available, returnsnull
. If this traverser is null-terminated, getting anull
means it's exhausted and will keep returningnull
forever. Otherwise, trying again later may produce one. -
map
@Nonnull @CheckReturnValue default <R> Traverser<R> map(@Nonnull Function<? super T, ? extends R> mapFn) Returns a traverser that will emit the results of applyingmapFn
to this traverser's items. IfmapFn
returnsnull
for an item, the returned traverser drops it and immediately moves on to the next item from this traverser. This waymapFn
can perform filtering in addition to transformation. -
filter
Returns a traverser that will emit the same items as this traverser, but only those that pass the given predicate. -
flatMap
@Nonnull @CheckReturnValue default <R> Traverser<R> flatMap(@Nonnull 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.The function must not return null traverser, but can return an empty traverser.
-
takeWhile
Returns a traverser that will emit a prefix of the original traverser, up to the item for which the predicate fails (exclusive). -
dropWhile
Returns a traverser that will emit a suffix of the original traverser, starting from the item for which the predicate fails (inclusive). -
append
Returns a traverser that will return all the items of this traverser, plus an additional item once this one returnsnull
. 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. -
prepend
Returns a traverser which prepends an additional item in front of all the items of this traverser. -
peek
Returns a traverser that will emit the same items as this traverser, additionally passing each (non-null) item to the supplied consumer. -
onFirstNull
Returns a traverser that will emit the same items as this traverser and additionally run the supplied action the first time this traverser returnsnull
.
-