@FunctionalInterface public interface Sequence<T> extends IterableCollection<T>
Iterable
sequence of elements with Stream
-like operations for refining, transforming and collating
the list of elements.Modifier and Type | Method and Description |
---|---|
default Sequence<java.util.Map.Entry<T,T>> |
adjacentEntries()
Pair the elements of this
Sequence into a sequence of Map.Entry elements. |
default Sequence<Pair<T,T>> |
adjacentPairs()
Pair the elements of this
Sequence into a sequence of Pair elements. |
default boolean |
all(java.lang.Class<?> target) |
default boolean |
all(java.util.function.Predicate<? super T> predicate) |
default boolean |
any(java.lang.Class<?> target) |
default boolean |
any(java.util.function.Predicate<? super T> predicate) |
default Sequence<T> |
append(java.lang.Iterable<T> iterable)
Append the elements of the given
Iterable to the end of this Sequence . |
default Sequence<T> |
append(java.util.Iterator<T> iterator)
Append the elements of the given
Iterator to the end of this Sequence . |
default Sequence<T> |
append(java.util.stream.Stream<T> stream)
Append the elements of the given
Stream to the end of this Sequence . |
default Sequence<T> |
append(T... items)
Append the given elements to the end of this
Sequence . |
default java.util.List<T> |
asList() |
default java.util.Optional<T> |
at(int index) |
default <U> java.util.Optional<U> |
at(int index,
java.lang.Class<? extends U> target) |
default java.util.Optional<T> |
at(int index,
java.util.function.Predicate<? super T> predicate) |
default Sequence<Sequence<T>> |
batch(java.util.function.BiPredicate<? super T,? super T> predicate)
Batch the elements of this
Sequence into a sequence of Sequence s of distinct elements, where the
given predicate determines where to split the lists of partitioned elements. |
default Sequence<Sequence<T>> |
batch(int size)
Batch the elements of this
Sequence into a sequence of Sequence s of distinct elements, each with
the given batch size. |
static <T> Sequence<T> |
cache(java.lang.Iterable<T> iterable)
Create a
Sequence with a cached copy of an Iterable of items. |
static <T> Sequence<T> |
cache(java.util.Iterator<T> iterator)
Create a
Sequence with a cached copy of an Iterator of items. |
static <T> Sequence<T> |
cache(java.util.stream.Stream<T> stream)
Create a
Sequence with a cached copy of a Stream of items. |
static Sequence<java.lang.Character> |
chars()
A
Sequence of all the Character values starting at Character.MIN_VALUE and ending at
Character.MAX_VALUE inclusive. |
static Sequence<java.lang.Character> |
charsFrom(char start)
A
Sequence of all the Character values starting at the given value and ending at Character.MAX_VALUE inclusive. |
default <R,A> R |
collect(java.util.stream.Collector<T,A,R> collector)
Collect this
Sequence into an arbitrary container using the given Collector . |
default <C> C |
collect(java.util.function.Supplier<? extends C> constructor,
java.util.function.BiConsumer<? super C,? super T> adder)
Collect this
Sequence into an arbitrary container using the given constructor and adder. |
default <C> C |
collectInto(C result,
java.util.function.BiConsumer<? super C,? super T> adder)
Collect this
Sequence into the given container, using the given adder. |
default <U extends java.util.Collection<T>> |
collectInto(U collection)
Collect this
Sequence into the given Collection . |
static <T> Sequence<T> |
concat(java.lang.Iterable<java.lang.Iterable<T>> iterables)
Create a concatenated
Sequence from several Iterable s which are concatenated together to form
the stream of items in the Sequence . |
static <T> Sequence<T> |
concat(java.lang.Iterable<T>... iterables)
Create a concatenated
Sequence from several Iterable s which are concatenated together to form
the stream of items in the Sequence . |
default boolean |
containsAll(java.lang.Iterable<? extends T> items) |
default boolean |
containsAll(T... items) |
default boolean |
containsAny(java.lang.Iterable<? extends T> items) |
default boolean |
containsAny(T... items) |
default <U,V> Sequence<U> |
delimit(V delimiter)
Delimit each element in this
Sequence with the given delimiter element. |
default <U,V> Sequence<U> |
delimit(V prefix,
V delimiter,
V suffix)
Delimit the elements in this
Sequence with the given delimiter, prefix and suffix elements. |
default Sequence<T> |
distinct() |
static <T> Sequence<T> |
empty()
Create an empty
Sequence with no items. |
default Sequence<T> |
endingAt(java.util.function.Predicate<T> terminal)
Terminate this
Sequence when the given predicate is satisfied, including the element that satisfies
the predicate as the last element in the Sequence . |
default Sequence<T> |
endingAt(T terminal)
Terminate this
Sequence when the given element is encountered, including the element as the last element
in the Sequence . |
default Sequence<T> |
endingAtNull()
Terminate this
Sequence when a null element is encountered, including the null as the last element
in the Sequence . |
default Sequence<java.util.Map.Entry<T,T>> |
entries()
Pair the elements of this
Sequence into a sequence of overlapping Map.Entry elements. |
default Sequence<T> |
excluding(java.lang.Iterable<? extends T> elements) |
default Sequence<T> |
excluding(T... elements) |
default <U> Sequence<U> |
filter(java.lang.Class<? extends U> target)
Filter the elements in this
Sequence , keeping only the elements are instances of the given
Class . |
default Sequence<T> |
filter(java.util.function.Predicate<? super T> predicate)
Filter the elements in this
Sequence , keeping only the elements that match the given Predicate . |
default Sequence<T> |
filterBack(java.util.function.BiPredicate<? super T,? super T> predicate)
Filter the elements in this
Sequence while peeking at the previous element in the iteration, keeping
only the elements that match the given BiPredicate . |
default Sequence<T> |
filterBack(T replacement,
java.util.function.BiPredicate<? super T,? super T> predicate)
Filter the elements in this
Sequence while peeking at the previous element in the iteration, keeping
only the elements that match the given BiPredicate . |
default Sequence<T> |
filterForward(java.util.function.BiPredicate<? super T,? super T> predicate)
Filter the elements in this
Sequence while peeking at the next element in the iteration, keeping
only the elements that match the given BiPredicate . |
default Sequence<T> |
filterForward(T replacement,
java.util.function.BiPredicate<? super T,? super T> predicate)
Filter the elements in this
Sequence while peeking at the next element in the iteration, keeping
only the elements that match the given BiPredicate . |
default Sequence<T> |
filterIndexed(ObjIntPredicate<? super T> predicate)
Filter the elements in this
Sequence , keeping only the elements that match the given
ObjIntPredicate , which is passed the current element and its index in the sequence. |
default java.util.Optional<T> |
first() |
default <U> java.util.Optional<U> |
first(java.lang.Class<? extends U> target) |
default java.util.Optional<T> |
first(java.util.function.Predicate<? super T> predicate) |
default <U> Sequence<U> |
flatten()
Flatten the elements in this
Sequence . |
default <U> Sequence<U> |
flatten(java.util.function.Function<? super T,? extends java.lang.Iterable<U>> mapper)
Flatten the elements in this
Sequence according to the given mapper Function . |
default void |
forEachIndexed(java.util.function.ObjIntConsumer<? super T> action)
Perform the given action for each element in this
Sequence , with the index of each element passed as the
second parameter in the action. |
static <T> Sequence<T> |
from(java.lang.Iterable<T> iterable)
Create a
Sequence from an Iterable of items. |
static <K,V> Sequence<java.util.Map.Entry<K,V>> |
from(java.util.Map<K,V> map)
Create a
Sequence of Map.Entry key/value items from a Map of items. |
static <T> Sequence<T> |
generate(java.util.function.Supplier<? extends T> supplier) |
default Sequence<T> |
including(java.lang.Iterable<? extends T> elements) |
default Sequence<T> |
including(T... elements) |
default BiSequence<java.lang.Integer,T> |
index() |
default <U> Sequence<Pair<T,U>> |
interleave(java.lang.Iterable<U> that)
Interleave the elements in this
Sequence with those of the given Iterable , stopping when either
sequence finishes. |
static Sequence<java.lang.Integer> |
ints()
A
Sequence of all the positive Integer numbers starting at 1 and ending at Integer.MAX_VALUE inclusive. |
static Sequence<java.lang.Integer> |
intsFrom(int start)
A
Sequence of all the Integer numbers starting at the given start and ending at Integer.MAX_VALUE inclusive. |
static Sequence<java.lang.Integer> |
intsFromZero()
A
Sequence of all the positive Integer numbers starting at 0 and ending at Integer.MAX_VALUE inclusive. |
default java.lang.String |
join()
Join this
Sequence into a string. |
default java.lang.String |
join(java.lang.String delimiter)
Join this
Sequence into a string separated by the given delimiter. |
default java.lang.String |
join(java.lang.String prefix,
java.lang.String delimiter,
java.lang.String suffix)
Join this
Sequence into a string separated by the given delimiter, with the given prefix and suffix. |
default java.util.Optional<T> |
last() |
default <U> java.util.Optional<U> |
last(java.lang.Class<? extends U> target) |
default java.util.Optional<T> |
last(java.util.function.Predicate<? super T> predicate) |
default Sequence<T> |
limit(int limit)
Limit the maximum number of results returned by this
Sequence . |
static Sequence<java.lang.Long> |
longs()
A
Sequence of all the positive Long numbers starting at 1 and ending at Long.MAX_VALUE inclusive. |
static Sequence<java.lang.Long> |
longsFrom(long start)
A
Sequence of all the Long numbers starting at the given value and ending at Long.MAX_VALUE inclusive. |
static Sequence<java.lang.Long> |
longsFromZero()
A
Sequence of all the positive Long numbers starting at 0 and ending at Long.MAX_VALUE inclusive. |
default <U> Sequence<U> |
map(java.util.function.Function<? super T,? extends U> mapper)
Map the values in this
Sequence to another set of values specified by the given mapper function. |
default <U> Sequence<U> |
mapBack(java.util.function.BiFunction<? super T,? super T,? extends U> mapper)
Map this
Sequence to another sequence while peeking at the previous element in the iteration. |
default <U> Sequence<U> |
mapBack(T replacement,
java.util.function.BiFunction<? super T,? super T,? extends U> mapper)
Map this
Sequence to another sequence while peeking at the previous element in the iteration. |
default <U> Sequence<U> |
mapForward(java.util.function.BiFunction<? super T,? super T,? extends U> mapper)
Map this
Sequence to another sequence while peeking at the following element in the iteration. |
default <U> Sequence<U> |
mapForward(T replacement,
java.util.function.BiFunction<? super T,? super T,? extends U> mapper)
Map this
Sequence to another sequence while peeking at the following element in the iteration. |
default <U> Sequence<U> |
mapIndexed(ObjIntFunction<? super T,? extends U> mapper)
Map the values in this
Sequence to another set of values specified by the given mapper function. |
default java.util.Optional<T> |
max() |
default java.util.Optional<T> |
max(java.util.Comparator<? super T> comparator) |
default java.util.Optional<T> |
min() |
default java.util.Optional<T> |
min(java.util.Comparator<? super T> comparator) |
static <T> Sequence<T> |
multiGenerate(java.util.function.Supplier<? extends java.util.function.Supplier<? extends T>> supplierSupplier) |
default boolean |
none(java.lang.Class<?> target) |
default boolean |
none(java.util.function.Predicate<? super T> predicate) |
static <T> Sequence<T> |
of(T... items)
Create a
Sequence with the given items. |
static <T> Sequence<T> |
of(T item)
Create a
Sequence with one item. |
static <T> Sequence<T> |
once(java.util.Iterator<T> iterator)
Create a one-pass-only
Sequence from an Iterator of items. |
static <T> Sequence<T> |
once(java.util.stream.Stream<T> stream)
Create a one-pass-only
Sequence from a Stream of items. |
default Sequence<Pair<T,T>> |
pairs()
Pair the elements of this
Sequence into a sequence of Pair elements. |
default Sequence<T> |
peek(java.util.function.Consumer<? super T> action)
Allow the given
Consumer to see each element in this Sequence as it is traversed. |
default Sequence<T> |
peekBack(java.util.function.BiConsumer<? super T,? super T> action)
Allow the given
BiConsumer to see each and its previous element in this Sequence as it is
traversed. |
default Sequence<T> |
peekBack(T replacement,
java.util.function.BiConsumer<? super T,? super T> action)
Allow the given
BiConsumer to see each and its previous element in this Sequence as it is
traversed. |
default Sequence<T> |
peekForward(java.util.function.BiConsumer<? super T,? super T> action)
Allow the given
BiConsumer to see each and its following element in this Sequence as it is
traversed. |
default Sequence<T> |
peekForward(T replacement,
java.util.function.BiConsumer<? super T,? super T> action)
Allow the given
BiConsumer to see each and its following element in this Sequence as it is
traversed. |
default Sequence<T> |
peekIndexed(java.util.function.ObjIntConsumer<? super T> action)
Allow the given
ObjIntConsumer to see each element with its index as this Sequence is
traversed. |
default <U,V> Sequence<U> |
prefix(V prefix)
Prefix the elements in this
Sequence with the given prefix element. |
static Sequence<java.lang.Character> |
range(char start,
char end)
A
Sequence of all the Character values between the given start and end positions, inclusive. |
static Sequence<java.lang.Integer> |
range(int start,
int end)
A
Sequence of all the Integer numbers between the given start and end positions, inclusive. |
static Sequence<java.lang.Long> |
range(long start,
long end)
A
Sequence of all the Long numbers between the given start and end positions, inclusive. |
static <T,S> Sequence<S> |
recurse(T seed,
java.util.function.Function<? super T,? extends S> f,
java.util.function.Function<? super S,? extends T> g)
Returns a
Sequence produced by recursively applying the given mapper f and incrementer
g operations to the given seed, the first element being f(seed) , the second being
f(g(f(seed))) , the third f(g(f(g(f(seed))))) and so on. |
static <T> Sequence<T> |
recurse(T seed,
java.util.function.UnaryOperator<T> f)
Returns a
Sequence produced by recursively applying the given operation to the given seed, which forms
the first element of the sequence, the second being f(seed) , the third [@code f(f(seed))} and so on. |
default java.util.Optional<T> |
reduce(java.util.function.BinaryOperator<T> operator)
Reduce this
Sequence into a single element by iteratively applying the given binary operator to
the current result and each element in this sequence. |
default T |
reduce(T identity,
java.util.function.BinaryOperator<T> operator)
Reduce this
Sequence into a single element by iteratively applying the given binary operator to
the current result and each element in this sequence, starting with the given identity as the initial result. |
default Sequence<T> |
repeat()
Repeat this
Sequence forever, producing a sequence that never terminates unless the original sequence is
empty in which case the resulting sequence is also empty. |
default Sequence<T> |
repeat(int times)
Repeat this
Sequence the given number of times. |
default Sequence<T> |
reverse() |
default Sequence<T> |
shuffle() |
default Sequence<T> |
shuffle(java.util.Random random) |
default Sequence<T> |
shuffle(java.util.function.Supplier<? extends java.util.Random> randomSupplier) |
default Sequence<T> |
skip(int skip)
Skip a set number of steps in this
Sequence . |
default Sequence<T> |
skipTail(int skip)
Skip a set number of steps at the end of this
Sequence . |
default Sequence<T> |
sorted() |
default Sequence<T> |
sorted(java.util.Comparator<? super T> comparator) |
default Sequence<Sequence<T>> |
split(java.util.function.Predicate<? super T> predicate)
Split the elements of this
Sequence into a sequence of Sequence s of distinct elements, where the
given predicate determines which elements to split the partitioned elements around. |
default Sequence<Sequence<T>> |
split(T element)
Split the elements of this
Sequence into a sequence of Sequence s of distinct elements, around
the given element. |
default java.util.Spliterator<T> |
spliterator() |
default Sequence<T> |
startingAfter(java.util.function.Predicate<? super T> predicate)
Begin this
Sequence just after the given predicate is satisfied, not including the element that
satisfies the predicate in the Sequence . |
default Sequence<T> |
startingAfter(T element)
Begin this
Sequence just after the given element is encountered, not including the element in the
Sequence . |
default Sequence<T> |
startingFrom(java.util.function.Predicate<? super T> predicate)
Begin this
Sequence when the given predicate is satisfied, including the element that satisfies
the predicate as the first element in the Sequence . |
default Sequence<T> |
startingFrom(T element)
Begin this
Sequence when the given element is encountered, including the element as the first element
in the Sequence . |
default Sequence<T> |
step(int step)
Skip x number of steps in between each invocation of the iterator of this
Sequence . |
default <U,V> Sequence<U> |
suffix(V suffix)
Suffix the elements in this
Sequence with the given suffix element. |
default Sequence<T> |
swap(java.util.function.BiPredicate<? super T,? super T> swapper)
Tests each pair of items in the sequence and swaps any two items which match the given predicate.
|
default <A> A[] |
toArray(java.util.function.IntFunction<? extends A[]> constructor)
Collect the elements in this
Sequence into an array of the type determined by the given array
constructor. |
default <L,R> BiSequence<L,R> |
toBiSequence()
|
default CharSeq |
toChars(ToCharFunction<? super T> mapper)
|
default <U extends java.util.Collection<T>> |
toCollection(java.util.function.Supplier<? extends U> constructor)
Collect this
Sequence into a Collection of the type determined by the given constructor. |
default DoubleSequence |
toDoubles(java.util.function.ToDoubleFunction<? super T> mapper)
Convert this
Sequence to a DoubleSequence using the given mapper function to map each element
to a double . |
default <K,V> EntrySequence<K,V> |
toEntrySequence()
|
default IntSequence |
toInts(java.util.function.ToIntFunction<? super T> mapper)
Convert this
Sequence to an IntSequence using the given mapper function to map each element
to an int . |
default java.util.List<T> |
toList()
Collect the elements in this
Sequence into a List . |
default java.util.List<T> |
toList(java.util.function.Supplier<? extends java.util.List<T>> constructor)
Collect the elements in this
Sequence into a List of the type determined by the given
constructor. |
default LongSequence |
toLongs(java.util.function.ToLongFunction<? super T> mapper)
Convert this
Sequence to a LongSequence using the given mapper function to map each element to a
long . |
default <K,V> java.util.Map<K,V> |
toMap()
Convert this
Sequence of Map.Entry values into a Map . |
default <K,V> java.util.Map<K,V> |
toMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper)
Convert this
Sequence of into a Map , using the given key mapper Function and value
mapper
Function to convert each element into a Map entry. |
default <M extends java.util.Map<K,V>,K,V> |
toMap(java.util.function.Supplier<? extends M> constructor)
Convert this
Sequence of Map.Entry values into a Map of the type determined by the given
constructor. |
default <M extends java.util.Map<K,V>,K,V> |
toMap(java.util.function.Supplier<? extends M> constructor,
java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper)
Convert this
Sequence of into a Map of the type determined by the given constructor, using the
given key mapper Function and value mapper Function to convert each element into a Map
entry. |
default java.util.Set<T> |
toSet()
Collect the elements in this
Sequence into a Set . |
default <S extends java.util.Set<T>> |
toSet(java.util.function.Supplier<? extends S> constructor)
Collect the elements in this
Sequence into a Set of the type determined by the given
constructor. |
default <K,V> java.util.SortedMap<K,V> |
toSortedMap()
Convert this
Sequence of Map.Entry into a SortedMap . |
default <K,V> java.util.SortedMap<K,V> |
toSortedMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper)
Convert this
Sequence into a SortedMap , using the given key mapper Function and value
mapper Function to convert each element into a SortedMap entry. |
default java.util.SortedSet<T> |
toSortedSet()
Collect the elements in this
Sequence into a SortedSet . |
default Sequence<T> |
until(java.util.function.Predicate<T> terminal)
Terminate this
Sequence just before the given predicate is satisfied, not including the element that
satisfies the predicate in the Sequence . |
default Sequence<T> |
until(T terminal)
Terminate this
Sequence just before the given element is encountered, not including the element in the
Sequence . |
default Sequence<T> |
untilNull()
Terminate this
Sequence just before a null element is encountered, not including the null in the
Sequence . |
default Sequence<Sequence<T>> |
window(int window)
Window the elements of this
Sequence into a sequence of Sequence s of elements, each with the
size of the given window. |
default Sequence<Sequence<T>> |
window(int window,
int step)
Window the elements of this
Sequence into a sequence of Sequence s of elements, each with the
size of the given window, stepping step elements between each window. |
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
static <T> Sequence<T> empty()
Sequence
with no items.empty
in interface IterableCollection<T>
of(Object)
,
of(Object...)
,
from(Iterable)
static <T> Sequence<T> of(T item)
Sequence
with one item.of
in interface IterableCollection<T>
of(Object...)
,
from(Iterable)
@SafeVarargs static <T> Sequence<T> of(T... items)
Sequence
with the given items.of
in interface IterableCollection<T>
of(Object)
,
from(Iterable)
static <T> Sequence<T> from(java.lang.Iterable<T> iterable)
Sequence
from an Iterable
of items.from
in interface IterableCollection<T>
of(Object)
,
of(Object...)
,
once(Iterator)
@SafeVarargs static <T> Sequence<T> concat(java.lang.Iterable<T>... iterables)
Sequence
from several Iterable
s which are concatenated together to form
the stream of items in the Sequence
.of(Object)
,
of(Object...)
,
from(Iterable)
static <T> Sequence<T> concat(java.lang.Iterable<java.lang.Iterable<T>> iterables)
Sequence
from several Iterable
s which are concatenated together to form
the stream of items in the Sequence
.of(Object)
,
of(Object...)
,
from(Iterable)
static <T> Sequence<T> once(java.util.Iterator<T> iterator)
Sequence
from an Iterator
of items. Note that Sequences
created
from Iterator
s will be exhausted when the given iterator has been passed over. Further attempts will
register the Sequence
as empty. If the sequence is terminated partway through iteration, further
calls to Collection.iterator()
will pick up where the previous iterator left off. If Collection.iterator()
calls
are interleaved, calls to the given iterator will be interleaved.of(Object)
,
of(Object...)
,
from(Iterable)
,
cache(Iterator)
static <T> Sequence<T> once(java.util.stream.Stream<T> stream)
Sequence
from a Stream
of items. Note that Sequences
created
from Stream
s will be exhausted when the given stream has been passed over. Further attempts will
register the Sequence
as empty. If the sequence is terminated partway through iteration, further
calls to Collection.iterator()
will pick up where the previous iterator left off. If Collection.iterator()
calls
are interleaved, calls to the given stream will be interleaved.of(Object)
,
of(Object...)
,
from(Iterable)
,
once(Iterator)
,
cache(Stream)
static <T> Sequence<T> cache(java.lang.Iterable<T> iterable)
Sequence
with a cached copy of an Iterable
of items.cache(Iterator)
,
cache(Stream)
,
from(Iterable)
static <T> Sequence<T> cache(java.util.Iterator<T> iterator)
Sequence
with a cached copy of an Iterator
of items.cache(Iterable)
,
cache(Stream)
,
once(Iterator)
static <T> Sequence<T> cache(java.util.stream.Stream<T> stream)
Sequence
with a cached copy of a Stream
of items.cache(Iterable)
,
cache(Iterator)
,
once(Stream)
static <K,V> Sequence<java.util.Map.Entry<K,V>> from(java.util.Map<K,V> map)
Sequence
of Map.Entry
key/value items from a Map
of items. The resulting
Sequence
can be mapped using Pair
items, which implement Map.Entry
and can thus be
processed as part of the Sequence
's transformation steps.of(T)
,
from(Iterable)
static Sequence<java.lang.Integer> ints()
Sequence
of all the positive Integer
numbers starting at 1
and ending at Integer.MAX_VALUE
inclusive.intsFromZero()
,
intsFrom(int)
,
range(int, int)
static Sequence<java.lang.Integer> intsFromZero()
Sequence
of all the positive Integer
numbers starting at 0
and ending at Integer.MAX_VALUE
inclusive.ints()
,
intsFrom(int)
,
range(int, int)
static Sequence<java.lang.Integer> intsFrom(int start)
Sequence
of all the Integer
numbers starting at the given start and ending at Integer.MAX_VALUE
inclusive.
The start value may be negative, in which case the sequence will continue towards positive numbers and
eventually Integer.MAX_VALUE
.
ints()
,
range(int, int)
static Sequence<java.lang.Integer> range(int start, int end)
Sequence
of all the Integer
numbers between the given start and end positions, inclusive.
If the end index is less than the start index, the resulting Sequence
will be counting down from the
start to the end.ints()
,
intsFromZero()
,
intsFrom(int)
static Sequence<java.lang.Long> longs()
Sequence
of all the positive Long
numbers starting at 1
and ending at Long.MAX_VALUE
inclusive.longsFromZero()
,
longsFrom(long)
,
range(long, long)
static Sequence<java.lang.Long> longsFromZero()
Sequence
of all the positive Long
numbers starting at 0
and ending at Long.MAX_VALUE
inclusive.longs()
,
longsFrom(long)
,
range(long, long)
static Sequence<java.lang.Long> longsFrom(long start)
Sequence
of all the Long
numbers starting at the given value and ending at Long.MAX_VALUE
inclusive.
The start value may be negative, in which case the sequence will continue towards positive numbers and
eventually Long.MAX_VALUE
.
longs()
,
longsFromZero()
,
range(long, long)
static Sequence<java.lang.Long> range(long start, long end)
Sequence
of all the Long
numbers between the given start and end positions, inclusive.
If the end index is less than the start index, the resulting Sequence
will be counting down from the
start to the end.longs()
,
longsFromZero()
,
longsFrom(long)
static Sequence<java.lang.Character> chars()
Sequence
of all the Character
values starting at Character.MIN_VALUE
and ending at
Character.MAX_VALUE
inclusive.charsFrom(char)
,
range(char, char)
static Sequence<java.lang.Character> charsFrom(char start)
Sequence
of all the Character
values starting at the given value and ending at Character.MAX_VALUE
inclusive.chars()
,
range(char, char)
static Sequence<java.lang.Character> range(char start, char end)
Sequence
of all the Character
values between the given start and end positions, inclusive.
If the end index is less than the start index, the resulting Sequence
will be counting down from the
start to the end.chars()
,
charsFrom(char)
static <T> Sequence<T> generate(java.util.function.Supplier<? extends T> supplier)
Sequence
generated by repeatedly calling the given supplier. The returned
Sequence
never terminates naturally. If Collection.iterator()
is called multiple times, further iterators
will pick up where the previous iterator left off in the given supplier. If iterator calls are interleaved,
calls to the supplier will be interleaved.multiGenerate(Supplier)
,
recurse(Object, UnaryOperator)
,
endingAt(Object)
,
until(Object)
static <T> Sequence<T> multiGenerate(java.util.function.Supplier<? extends java.util.function.Supplier<? extends T>> supplierSupplier)
Sequence
where each Collection.iterator()
is generated by polling for a supplier and
then using it to generate the sequence of elements. The sequence never terminates.generate(Supplier)
,
recurse(Object, UnaryOperator)
,
endingAt(Object)
,
until(Object)
static <T> Sequence<T> recurse(T seed, java.util.function.UnaryOperator<T> f)
Sequence
produced by recursively applying the given operation to the given seed, which forms
the first element of the sequence, the second being f(seed)
, the third [@code f(f(seed))} and so on.
The returned Sequence
never terminates naturally.Sequence
produced by recursively applying the given operation to the given seedrecurse(Object, Function, Function)
,
multiGenerate(Supplier)
,
endingAt(Object)
,
until(Object)
static <T,S> Sequence<S> recurse(T seed, java.util.function.Function<? super T,? extends S> f, java.util.function.Function<? super S,? extends T> g)
Sequence
produced by recursively applying the given mapper f
and incrementer
g
operations to the given seed, the first element being f(seed)
, the second being
f(g(f(seed)))
, the third f(g(f(g(f(seed)))))
and so on. The returned Sequence
never
terminates naturally.f
- a mapper function for producing elements that are to be included in the sequence, the first being
f(seed)g
- an incrementer function for producing the next unmapped element to be included in the sequence,
applied to the first mapped element f(seed) to produce the second unmapped valueSequence
produced by recursively applying the given mapper and incrementer operations to the
given seedrecurse(Object, UnaryOperator)
,
endingAt(Object)
,
until(Object)
default java.util.Spliterator<T> spliterator()
spliterator
in interface java.util.Collection<T>
spliterator
in interface java.lang.Iterable<T>
spliterator
in interface IterableCollection<T>
default Sequence<T> until(T terminal)
Sequence
just before the given element is encountered, not including the element in the
Sequence
.default Sequence<T> endingAt(T terminal)
Sequence
when the given element is encountered, including the element as the last element
in the Sequence
.default Sequence<T> untilNull()
Sequence
just before a null element is encountered, not including the null in the
Sequence
.default Sequence<T> endingAtNull()
Sequence
when a null element is encountered, including the null as the last element
in the Sequence
.default Sequence<T> until(java.util.function.Predicate<T> terminal)
Sequence
just before the given predicate is satisfied, not including the element that
satisfies the predicate in the Sequence
.default Sequence<T> endingAt(java.util.function.Predicate<T> terminal)
Sequence
when the given predicate is satisfied, including the element that satisfies
the predicate as the last element in the Sequence
.default Sequence<T> startingAfter(T element)
Sequence
just after the given element is encountered, not including the element in the
Sequence
.startingAfter(Predicate)
,
startingFrom(Object)
default Sequence<T> startingFrom(T element)
Sequence
when the given element is encountered, including the element as the first element
in the Sequence
.startingFrom(Predicate)
,
startingAfter(Object)
default Sequence<T> startingAfter(java.util.function.Predicate<? super T> predicate)
Sequence
just after the given predicate is satisfied, not including the element that
satisfies the predicate in the Sequence
.startingAfter(Object)
,
startingFrom(Predicate)
default Sequence<T> startingFrom(java.util.function.Predicate<? super T> predicate)
Sequence
when the given predicate is satisfied, including the element that satisfies
the predicate as the first element in the Sequence
.startingFrom(Object)
,
startingAfter(Predicate)
default <U> Sequence<U> map(java.util.function.Function<? super T,? extends U> mapper)
Sequence
to another set of values specified by the given mapper
function.default <U> Sequence<U> mapIndexed(ObjIntFunction<? super T,? extends U> mapper)
Sequence
to another set of values specified by the given mapper
function.
In addition to the current element, the mapper has access to the index of each element.default <U> Sequence<U> mapBack(java.util.function.BiFunction<? super T,? super T,? extends U> mapper)
Sequence
to another sequence while peeking at the previous element in the iteration.
The mapper has access to the previous element and the next element in the iteration. null
is provided
as the first previous value when the next element is the first value in the sequence.
mapBack(Object, BiFunction)
default <U> Sequence<U> mapForward(java.util.function.BiFunction<? super T,? super T,? extends U> mapper)
Sequence
to another sequence while peeking at the following element in the iteration.
The mapper has access to the next element and the following element in the iteration. null
is
provided as the last following value when the next element is the last value in the sequence.
mapForward(Object, BiFunction)
default <U> Sequence<U> mapBack(T replacement, java.util.function.BiFunction<? super T,? super T,? extends U> mapper)
Sequence
to another sequence while peeking at the previous element in the iteration.
The mapper has access to the previous element and the next element in the iteration. The given replacement value is provided as a prefix to the sequence for the first value in the sequence.
mapBack(BiFunction)
default <U> Sequence<U> mapForward(T replacement, java.util.function.BiFunction<? super T,? super T,? extends U> mapper)
Sequence
to another sequence while peeking at the following element in the iteration.
The mapper has access to the next element and the following element in the iteration. The given replacement value is provided as a suffix to the sequence for the last value in the sequence.
mapForward(BiFunction)
default Sequence<T> skipTail(int skip)
Sequence
.default Sequence<T> limit(int limit)
Sequence
.default Sequence<T> append(T... items)
Sequence
.default Sequence<T> append(java.lang.Iterable<T> iterable)
Iterable
to the end of this Sequence
.cache(Iterable)
default Sequence<T> append(java.util.Iterator<T> iterator)
Iterator
to the end of this Sequence
.
The appended elements will only be available on the first traversal of the resulting Sequence
.
cache(Iterator)
default Sequence<T> append(java.util.stream.Stream<T> stream)
Stream
to the end of this Sequence
.
The appended elements will only be available on the first traversal of the resulting Sequence
.
cache(Stream)
default Sequence<T> filter(java.util.function.Predicate<? super T> predicate)
Sequence
, keeping only the elements that match the given Predicate
.default Sequence<T> filterIndexed(ObjIntPredicate<? super T> predicate)
Sequence
, keeping only the elements that match the given
ObjIntPredicate
, which is passed the current element and its index in the sequence.default <U> Sequence<U> filter(java.lang.Class<? extends U> target)
Sequence
, keeping only the elements are instances of the given
Class
.default Sequence<T> filterBack(java.util.function.BiPredicate<? super T,? super T> predicate)
Sequence
while peeking at the previous element in the iteration, keeping
only the elements that match the given BiPredicate
.
The predicate has access to the previous element and the next element in the iteration. null
is provided
as a prefix to the sequence for first value in the sequence.
filterBack(Object, BiPredicate)
default Sequence<T> filterBack(T replacement, java.util.function.BiPredicate<? super T,? super T> predicate)
Sequence
while peeking at the previous element in the iteration, keeping
only the elements that match the given BiPredicate
.
The predicate has access to the previous element and the next element in the iteration. The given replacement value is provided as a prefix to the sequence for the first value in the sequence.
filterBack(BiPredicate)
default Sequence<T> filterForward(java.util.function.BiPredicate<? super T,? super T> predicate)
Sequence
while peeking at the next element in the iteration, keeping
only the elements that match the given BiPredicate
.
The predicate has access to the current element and the next element in the iteration. null
is provided
as a suffix to the sequence for the last value in the sequence.
filterForward(Object, BiPredicate)
default Sequence<T> filterForward(T replacement, java.util.function.BiPredicate<? super T,? super T> predicate)
Sequence
while peeking at the next element in the iteration, keeping
only the elements that match the given BiPredicate
.
The predicate has access to the current element and the next element in the iteration. The given replacement value is provided as a suffix to the sequence for the last value in the sequence.
filterForward(BiPredicate)
default Sequence<T> including(T... elements)
Sequence
containing only the elements found in the given target array.default Sequence<T> including(java.lang.Iterable<? extends T> elements)
Sequence
containing only the elements found in the given target iterable.default Sequence<T> excluding(T... elements)
Sequence
containing only the elements not found in the given target array.default Sequence<T> excluding(java.lang.Iterable<? extends T> elements)
Sequence
containing only the elements not found in the given target iterable.default <U> Sequence<U> flatten(java.util.function.Function<? super T,? extends java.lang.Iterable<U>> mapper)
Sequence
according to the given mapper Function
. The resulting
Sequence
contains the elements that is the result of applying the mapper Function
to each
element, appended together inline as a single Sequence
.default <U> Sequence<U> flatten()
Sequence
. The resulting Sequence
contains the elements that is the
result of flattening each element, inline. Allowed elements that can be flattened are Iterator
,
Iterable
, object array
, Pair
, Map.Entry
and Stream
. Elements of another type
will result in a ClassCastException
.java.lang.ClassCastException
- if a non-collection element is encountered in the Sequence
.flatten(Function)
,
map(Function)
,
toChars(ToCharFunction)
,
toInts(ToIntFunction)
,
toLongs(ToLongFunction)
,
toDoubles(ToDoubleFunction)
default <A> A[] toArray(java.util.function.IntFunction<? extends A[]> constructor)
Sequence
into an array of the type determined by the given array
constructor.default java.util.List<T> toList()
Sequence
into a List
.default java.util.List<T> toList(java.util.function.Supplier<? extends java.util.List<T>> constructor)
Sequence
into a List
of the type determined by the given
constructor.default java.util.Set<T> toSet()
Sequence
into a Set
.default <S extends java.util.Set<T>> S toSet(java.util.function.Supplier<? extends S> constructor)
Sequence
into a Set
of the type determined by the given
constructor.default java.util.SortedSet<T> toSortedSet()
Sequence
into a SortedSet
.default <K,V> java.util.Map<K,V> toMap()
Sequence
of Map.Entry
values into a Map
.java.lang.ClassCastException
- if this Sequence
is not of Map.Entry
.default <M extends java.util.Map<K,V>,K,V> M toMap(java.util.function.Supplier<? extends M> constructor)
Sequence
of Map.Entry
values into a Map
of the type determined by the given
constructor.java.lang.ClassCastException
- if this Sequence
is not of Map.Entry
.default <K,V> java.util.Map<K,V> toMap(java.util.function.Function<? super T,? extends K> keyMapper, java.util.function.Function<? super T,? extends V> valueMapper)
Sequence
of into a Map
, using the given key mapper Function
and value
mapper
Function
to convert each element into a Map
entry.default <M extends java.util.Map<K,V>,K,V> M toMap(java.util.function.Supplier<? extends M> constructor, java.util.function.Function<? super T,? extends K> keyMapper, java.util.function.Function<? super T,? extends V> valueMapper)
Sequence
of into a Map
of the type determined by the given constructor, using the
given key mapper Function
and value mapper Function
to convert each element into a Map
entry.default <K,V> java.util.SortedMap<K,V> toSortedMap()
Sequence
of Map.Entry
into a SortedMap
.java.lang.ClassCastException
- if this Sequence
is not of Map.Entry
.default <K,V> java.util.SortedMap<K,V> toSortedMap(java.util.function.Function<? super T,? extends K> keyMapper, java.util.function.Function<? super T,? extends V> valueMapper)
Sequence
into a SortedMap
, using the given key mapper Function
and value
mapper Function
to convert each element into a SortedMap
entry.default <U extends java.util.Collection<T>> U toCollection(java.util.function.Supplier<? extends U> constructor)
Sequence
into a Collection
of the type determined by the given constructor.default <C> C collect(java.util.function.Supplier<? extends C> constructor, java.util.function.BiConsumer<? super C,? super T> adder)
Sequence
into an arbitrary container using the given constructor and adder.default <R,A> R collect(java.util.stream.Collector<T,A,R> collector)
Sequence
into an arbitrary container using the given Collector
.default <U extends java.util.Collection<T>> U collectInto(U collection)
Sequence
into the given Collection
.default <C> C collectInto(C result, java.util.function.BiConsumer<? super C,? super T> adder)
Sequence
into the given container, using the given adder.default java.util.List<T> asList()
List
view of this Sequence
, which is updated in real time as the backing store of the
Sequence
changes. The list does not implement RandomAccess
and is best accessed in sequence.default java.lang.String join()
Sequence
into a string.default java.lang.String join(java.lang.String delimiter)
Sequence
into a string separated by the given delimiter.default java.lang.String join(java.lang.String prefix, java.lang.String delimiter, java.lang.String suffix)
Sequence
into a string separated by the given delimiter, with the given prefix and suffix.default java.util.Optional<T> reduce(java.util.function.BinaryOperator<T> operator)
Sequence
into a single element by iteratively applying the given binary operator to
the current result and each element in this sequence.default T reduce(T identity, java.util.function.BinaryOperator<T> operator)
Sequence
into a single element by iteratively applying the given binary operator to
the current result and each element in this sequence, starting with the given identity as the initial result.default java.util.Optional<T> first()
Sequence
or an empty Optional
if there are no elements in the
Sequence
.default java.util.Optional<T> last()
Sequence
or an empty Optional
if there are no
elements in the Sequence
.default java.util.Optional<T> at(int index)
Optional
if the Sequence
is smaller than
the index.default java.util.Optional<T> first(java.util.function.Predicate<? super T> predicate)
Sequence
that matches the given predicate, or an empty
Optional
if there are no matching elements in the Sequence
.default java.util.Optional<T> last(java.util.function.Predicate<? super T> predicate)
Sequence
the matches the given predicate, or an empty Optional
if there are no matching elements in the Sequence
.default java.util.Optional<T> at(int index, java.util.function.Predicate<? super T> predicate)
Optional
if the Sequence
of matching elements is smaller than the index.default <U> java.util.Optional<U> first(java.lang.Class<? extends U> target)
Sequence
that is an instance of the given Class
, or an empty
Optional
if there are no matching elements in the Sequence
.default <U> java.util.Optional<U> last(java.lang.Class<? extends U> target)
Sequence
that is an instance of the given Class
, or an empty
Optional
if there are no matching elements in the Sequence
.default <U> java.util.Optional<U> at(int index, java.lang.Class<? extends U> target)
Class
, or an
empty Optional
if the Sequence
of matching elements is smaller than the index.default Sequence<java.util.Map.Entry<T,T>> entries()
Sequence
into a sequence of overlapping Map.Entry
elements. Each entry
overlaps the value item with the key item of the next entry. If there is only one item in the sequence, the
first entry returned has that item as a key and null as the value.default Sequence<Pair<T,T>> pairs()
Sequence
into a sequence of Pair
elements. Each pair overlaps the
second item with the first item of the next pair. If there is only one item in the list, the first pair returned
has a null as the second item.default Sequence<java.util.Map.Entry<T,T>> adjacentEntries()
Sequence
into a sequence of Map.Entry
elements. Each entry is adjacent to
the next entry. If there is an uneven amount of items in the list, the final entry returned has a null as the
value item.default Sequence<Pair<T,T>> adjacentPairs()
Sequence
into a sequence of Pair
elements. Each pair is adjacent to
the next pair. If there is an uneven amount of items in the list, the final pair returned has a null as the
second item.default <L,R> BiSequence<L,R> toBiSequence()
Sequence
of Pair
s of items into a BiSequence
. Note the sequence must be of
Pair
or a ClassCastException
will occur when traversal is attempted.default <K,V> EntrySequence<K,V> toEntrySequence()
Sequence
of Map.Entry
items into an EntrySequence
. Note the sequence must be
of Map.Entry
or a ClassCastException
will occur when traversal is attempted.default Sequence<Sequence<T>> window(int window)
Sequence
into a sequence of Sequence
s of elements, each with the
size of the given window. The first item in each sequence is the second item in the previous sequence. The final
sequence may be shorter than the window. This method is equivalent to window(window, 1)
.default Sequence<Sequence<T>> window(int window, int step)
Sequence
into a sequence of Sequence
s of elements, each with the
size of the given window, stepping step
elements between each window. If the given step is less than the
window size, the windows will overlap each other. If the step is larger than the window size, elements will be
skipped in between windows.default Sequence<Sequence<T>> batch(int size)
Sequence
into a sequence of Sequence
s of distinct elements, each with
the given batch size. This method is equivalent to window(size, size)
.default Sequence<Sequence<T>> batch(java.util.function.BiPredicate<? super T,? super T> predicate)
Sequence
into a sequence of Sequence
s of distinct elements, where the
given predicate determines where to split the lists of partitioned elements. The predicate is given the current
and next item in the iteration, and if it returns true a partition is created between the elements.default Sequence<Sequence<T>> split(T element)
Sequence
into a sequence of Sequence
s of distinct elements, around
the given element. The elements around which the sequence is split are not included in the result.default Sequence<Sequence<T>> split(java.util.function.Predicate<? super T> predicate)
Sequence
into a sequence of Sequence
s of distinct elements, where the
given predicate determines which elements to split the partitioned elements around. The elements matching the
predicate are not included in the result.default Sequence<T> step(int step)
Sequence
.default Sequence<T> distinct()
Sequence
where each item in this Sequence
occurs only once, the first time it is
encountered.default Sequence<T> sorted()
Sequence
sorted according to the natural order. Must be a (@code Sequence} of
Comparable
or a ClassCastException
is thrown during traversal.default Sequence<T> sorted(java.util.Comparator<? super T> comparator)
Sequence
sorted according to the given Comparator
.default java.util.Optional<T> min()
Sequence
according to their natural order. Elements in the sequence
must all implement Comparable
or a ClassCastException
will be thrown at traversal.default java.util.Optional<T> max()
Sequence
according to their natural order. Elements in the sequence
must all implement Comparable
or a ClassCastException
will be thrown at traversal.default java.util.Optional<T> min(java.util.Comparator<? super T> comparator)
Sequence
according to the given Comparator
.default java.util.Optional<T> max(java.util.Comparator<? super T> comparator)
Sequence
according to the given Comparator
.default boolean all(java.util.function.Predicate<? super T> predicate)
Sequence
satisfy the given predicate, false otherwise.default boolean none(java.util.function.Predicate<? super T> predicate)
Sequence
satisfy the given predicate, false otherwise.default boolean any(java.util.function.Predicate<? super T> predicate)
Sequence
satisfies the given predicate, false otherwise.default boolean all(java.lang.Class<?> target)
Sequence
are instances of the given Class
, false otherwise.default boolean none(java.lang.Class<?> target)
Sequence
are instances of the given Class
, false otherwise.default boolean any(java.lang.Class<?> target)
Sequence
is an instance of the given Class
, false otherwise.default Sequence<T> peek(java.util.function.Consumer<? super T> action)
Consumer
to see each element in this Sequence
as it is traversed.default Sequence<T> peekIndexed(java.util.function.ObjIntConsumer<? super T> action)
ObjIntConsumer
to see each element with its index as this Sequence
is
traversed.default Sequence<T> peekForward(java.util.function.BiConsumer<? super T,? super T> action)
BiConsumer
to see each and its following element in this Sequence
as it is
traversed. In the last iteration, the following item will be null.peekForward(Object, BiConsumer)
default Sequence<T> peekBack(java.util.function.BiConsumer<? super T,? super T> action)
BiConsumer
to see each and its previous element in this Sequence
as it is
traversed. In the first iteration, the previous item will be null.peekBack(Object, BiConsumer)
default Sequence<T> peekForward(T replacement, java.util.function.BiConsumer<? super T,? super T> action)
BiConsumer
to see each and its following element in this Sequence
as it is
traversed. In the last iteration, the following item will have the given replacement value.peekForward(BiConsumer)
default Sequence<T> peekBack(T replacement, java.util.function.BiConsumer<? super T,? super T> action)
BiConsumer
to see each and its previous element in this Sequence
as it is
traversed. In the first iteration, the previous item will have the given replacement value.peekBack(BiConsumer)
default <U,V> Sequence<U> delimit(V delimiter)
Sequence
with the given delimiter element.default <U,V> Sequence<U> delimit(V prefix, V delimiter, V suffix)
Sequence
with the given delimiter, prefix and suffix elements.default <U,V> Sequence<U> prefix(V prefix)
Sequence
with the given prefix element.default <U,V> Sequence<U> suffix(V suffix)
Sequence
with the given suffix element.default <U> Sequence<Pair<T,U>> interleave(java.lang.Iterable<U> that)
Sequence
with those of the given Iterable
, stopping when either
sequence finishes. The result is a Sequence
of pairs of items, the left entry coming from this
sequence and the right entry from the given iterable.default Sequence<T> reverse()
Sequence
which iterates over this Sequence
in reverse order.default Sequence<T> shuffle()
Sequence
which iterates over this Sequence
in random order.default Sequence<T> shuffle(java.util.Random random)
Sequence
which iterates over this Sequence
in random order as determined by the given
random generator.default Sequence<T> shuffle(java.util.function.Supplier<? extends java.util.Random> randomSupplier)
Sequence
which iterates over this Sequence
in random order as determined by the given
random generator. A new instance of Random
is created by the given supplier at the start of each
iteration.default CharSeq toChars(ToCharFunction<? super T> mapper)
default IntSequence toInts(java.util.function.ToIntFunction<? super T> mapper)
Sequence
to an IntSequence
using the given mapper function to map each element
to an int
.default LongSequence toLongs(java.util.function.ToLongFunction<? super T> mapper)
Sequence
to a LongSequence
using the given mapper function to map each element to a
long
.default DoubleSequence toDoubles(java.util.function.ToDoubleFunction<? super T> mapper)
Sequence
to a DoubleSequence
using the given mapper function to map each element
to a double
.default Sequence<T> repeat()
Sequence
forever, producing a sequence that never terminates unless the original sequence is
empty in which case the resulting sequence is also empty.default Sequence<T> swap(java.util.function.BiPredicate<? super T,? super T> swapper)
default BiSequence<java.lang.Integer,T> index()
BiSequence
of this sequence paired up with the index of each element.default boolean containsAll(T... items)
Sequence
contains all of the given items, false otherwise.default boolean containsAll(java.lang.Iterable<? extends T> items)
Sequence
contains all of the given items, false otherwise.default boolean containsAny(T... items)
Sequence
contains any of the given items, false otherwise.default boolean containsAny(java.lang.Iterable<? extends T> items)
Sequence
contains any of the given items, false otherwise.default void forEachIndexed(java.util.function.ObjIntConsumer<? super T> action)
Sequence
, with the index of each element passed as the
second parameter in the action.