@FunctionalInterface public interface IntSequence extends IntIterable
Iterable sequence of int values with Stream-like operations for refining,
transforming and collating the list of ints.| Modifier and Type | Method and Description |
|---|---|
default boolean |
all(java.util.function.IntPredicate predicate) |
default boolean |
any(java.util.function.IntPredicate predicate) |
default IntSequence |
append(int... ints)
Append the given
ints to the end of this IntSequence. |
default IntSequence |
append(IntIterable that)
|
default IntSequence |
append(IntIterator iterator)
|
default IntSequence |
append(java.util.stream.IntStream stream)
Append the
int values of the given IntStream to the end of this IntSequence. |
default IntSequence |
append(java.lang.Iterable<java.lang.Integer> iterable)
Append the
Integers in the given Iterable to the end of this IntSequence. |
default IntSequence |
append(java.util.Iterator<java.lang.Integer> iterator)
Append the
Integers in the given Iterator to the end of this IntSequence. |
default IntSequence |
append(java.util.stream.Stream<java.lang.Integer> stream)
Append the
Integers in the given Stream to the end of this IntSequence. |
default Sequence<IntSequence> |
batch(int size)
Batch the elements of this
IntSequence into a sequence of IntSequences of distinct elements,
each with the given batch size. |
default Sequence<IntSequence> |
batch(IntBiPredicate predicate)
Batch the elements of this
IntSequence into a sequence of IntSequences of distinct elements,
where the given predicate determines where to split the lists of partitioned elements. |
default Sequence<java.lang.Integer> |
box()
Map the
ints in this IntSequence to their boxed Integer counterparts. |
default <C> C |
collect(java.util.function.Supplier<? extends C> constructor,
java.util.function.ObjIntConsumer<? super C> adder)
Collect this
IntSequence into an arbitrary container using the given constructor and adder. |
default <C> C |
collectInto(C result,
java.util.function.ObjIntConsumer<? super C> adder)
Collect this
IntSequence into the given container using the given adder. |
default long |
count() |
static IntSequence |
decreasingFrom(int start)
A decreasing
Sequence of int values starting at the given value. |
default IntSequence |
distinct() |
static IntSequence |
empty()
Create empty
IntSequence with no contents. |
default IntSequence |
endingAt(int terminal)
Terminate this
IntSequence sequence at the given element, including it as the last element in this
IntSequence sequence. |
default IntSequence |
endingAt(java.util.function.IntPredicate terminal)
Terminate this
IntSequence sequence at the element that satisfies the given predicate, including the
element as the last element in this IntSequence sequence. |
default IntSequence |
filter(java.util.function.IntPredicate predicate)
Filter the elements in this
IntSequence, keeping only the elements that match the given
IntPredicate. |
default IntSequence |
filterBack(int firstPrevious,
IntBiPredicate predicate)
Filter this
IntSequence to another sequence of ints while peeking at the previous value in the
sequence. |
default IntSequence |
filterForward(int lastNext,
IntBiPredicate predicate)
Filter this
IntSequence to another sequence of ints while peeking at the next int in the sequence. |
default java.util.OptionalInt |
first() |
static IntSequence |
from(IntIterable iterable)
Create a
IntSequence from a IntIterable. |
static IntSequence |
from(IntIterator iterator)
Create a
IntSequence from a IntIterator of int values. |
static IntSequence |
from(java.lang.Iterable<java.lang.Integer> iterable)
Create a
IntSequence from an Iterable of Integer values. |
static IntSequence |
from(java.util.Iterator<java.lang.Integer> iterator)
Create an
IntSequence from an Iterator of Integer values. |
static IntSequence |
from(java.util.stream.Stream<java.lang.Integer> stream)
Create a
Sequence from a Stream of items. |
static IntSequence |
from(java.util.function.Supplier<? extends IntIterator> iteratorSupplier)
Create a
Sequence from Iterators of items supplied by the given Supplier. |
static IntSequence |
generate(java.util.function.IntSupplier supplier) |
static IntSequence |
increasingFrom(int start)
An increasing
IntSequence of int values starting at the given value. |
default IntSequence |
interleave(IntSequence that)
Interleave the elements in this
IntSequence with those of the given IntSequence, stopping when
either sequence finishes. |
default java.lang.String |
join(java.lang.String delimiter)
Join this
IntSequence 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
IntSequence into a string separated by the given delimiter, with the given prefix and suffix. |
default java.util.OptionalInt |
last() |
default IntSequence |
limit(long limit)
Limit the maximum number of
ints returned by this IntSequence. |
default IntSequence |
map(java.util.function.IntUnaryOperator mapper)
Map the values in this
IntSequence sequence to another set of values specified by the given mapper
function. |
default IntSequence |
mapBack(int firstPrevious,
java.util.function.IntBinaryOperator mapper)
Map this
IntSequence to another sequence of ints while peeking at the previous value in the
sequence. |
default IntSequence |
mapForward(int lastNext,
java.util.function.IntBinaryOperator mapper)
Map this
IntSequence to another sequence of ints while peeking at the next int in the sequence. |
default java.util.OptionalInt |
max() |
default java.util.OptionalInt |
min() |
static IntSequence |
negative()
An
IntSequence of all the negative int values starting at -1 and ending at
Integer.MIN_VALUE. |
static IntSequence |
negativeFromZero()
An
IntSequence of all the negative int values starting at 0 and ending at
Integer.MIN_VALUE. |
default boolean |
none(java.util.function.IntPredicate predicate) |
static IntSequence |
of(int... cs)
Create a
IntSequence with the given ints. |
default IntSequence |
peek(java.util.function.IntConsumer action)
Allow the given
IntConsumer to see each element in this IntSequence as it is traversed. |
static IntSequence |
positive()
An
IntSequence of all the positive int values starting at 1 and ending at
Integer.MAX_VALUE. |
static IntSequence |
positiveFromZero()
An
IntSequence of all the positive int values starting at 0 and ending at
Integer.MAX_VALUE. |
default IntSequence |
prefix(int... cs)
Prefix the ints in this
IntSequence with the given ints. |
static IntSequence |
range(int start,
int end)
A
Sequence of all the int values between the given start and end positions, inclusive. |
static IntSequence |
range(int start,
int end,
int step)
A
Sequence of the int values between the given start and end positions, stepping with the
given step. |
static IntSequence |
recurse(int seed,
java.util.function.IntUnaryOperator op)
Returns an
IntSequence 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 f(f(seed)) and so on. |
default java.util.OptionalInt |
reduce(java.util.function.IntBinaryOperator operator)
Reduce this
IntSequence into a single int by iteratively applying the given binary operator to
the current result and each int in the sequence. |
default int |
reduce(int identity,
java.util.function.IntBinaryOperator operator)
Reduce this
IntSequence into a single int by iteratively applying the given binary operator to
the current result and each int in the sequence, starting with the given identity as the initial result. |
default void |
removeAll()
Remove all elements matched by this sequence using
Iterator.remove(). |
default IntSequence |
repeat()
Repeat this sequence of ints forever, looping back to the beginning when the iterator runs out of ints.
|
default IntSequence |
repeat(long times)
Repeat this sequence of ints x times, looping back to the beginning when the iterator runs out of ints.
|
default IntSequence |
reverse() |
default java.util.OptionalInt |
second() |
default IntSequence |
skip(long skip)
Skip a set number of
ints in this IntSequence. |
default IntSequence |
sorted() |
default IntSequence |
step(long step)
Skip x number of steps in between each invocation of the iterator of this
IntSequence. |
static IntSequence |
steppingFrom(int start,
int step)
A
Sequence of all the int values starting at the given value and stepping with the given
step. |
default IntSequence |
suffix(int... cs)
Suffix the ints in this
IntSequence with the given ints. |
default java.util.OptionalInt |
third() |
default int[] |
toArray()
Collect the ints in this
IntSequence into an array. |
default CharSeq |
toChars()
Convert this sequence of ints to a sequence of chars corresponding to the downcast char value of each int.
|
default CharSeq |
toChars(IntToCharFunction mapper)
Convert this sequence of ints to a sequence of chars using the given converter function.
|
default DoubleSequence |
toDoubles()
Convert this sequence of ints to a sequence of doubles corresponding to the cast double value of each int.
|
default DoubleSequence |
toDoubles(java.util.function.IntToDoubleFunction mapper)
Convert this sequence of ints to a sequence of doubles using the given converter function.
|
default LongSequence |
toLongs()
Convert this sequence of ints to a sequence of longs.
|
default LongSequence |
toLongs(java.util.function.IntToLongFunction mapper)
Convert this sequence of ints to a sequence of longs using the given converter function.
|
default <T> Sequence<T> |
toSequence(java.util.function.IntFunction<T> mapper)
|
default IntSequence |
until(int terminal)
Terminate this
IntSequence sequence before the given element, with the previous element as the last
element in this IntSequence sequence. |
default IntSequence |
until(java.util.function.IntPredicate terminal)
Terminate this
IntSequence sequence before the element that satisfies the given predicate, with the
previous
element as the last element in this IntSequence sequence. |
default Sequence<IntSequence> |
window(int window)
Window the elements of this
IntSequence into a sequence of IntSequences of elements, each with
the size of the given window. |
default Sequence<IntSequence> |
window(int window,
int step)
Window the elements of this
IntSequence into a sequence of IntSequences of elements, each with
the size of the given window, stepping step elements between each window. |
forEach, forEachInt, from, from, from, iteratorstatic IntSequence empty()
IntSequence with no contents.static IntSequence from(java.util.Iterator<java.lang.Integer> iterator)
IntSequence from an Iterator of Integer values. Note that IntSequence
created
from
Iterators cannot be passed over more than once. Further attempts will register the IntSequence as empty.from in interface IntIterablestatic IntSequence from(IntIterator iterator)
IntSequence from a IntIterator of int values. Note that IntSequences created from IntIterators cannot be passed over more than once. Further attempts
will
register the IntSequence as empty.from in interface IntIterablestatic IntSequence from(IntIterable iterable)
IntSequence from a IntIterable.static IntSequence of(int... cs)
IntSequence with the given ints.of in interface IntIterablestatic IntSequence from(java.util.function.Supplier<? extends IntIterator> iteratorSupplier)
Sequence from Iterators of items supplied by the given Supplier. Every time
the Sequence is to be iterated over, the Supplier is used to create the initial stream of
elements. This is similar to creating a Sequence from an Iterable.static IntSequence from(java.util.stream.Stream<java.lang.Integer> stream)
Sequence from a Stream of items. Note that Sequences created from Streams cannot be passed over more than once. Further attempts will cause an IllegalStateException
when the Stream is requested again.from in interface IntIterablejava.lang.IllegalStateException - if the Stream is exhausted.static IntSequence from(java.lang.Iterable<java.lang.Integer> iterable)
IntSequence from an Iterable of Integer values.from in interface IntIterablestatic IntSequence positive()
IntSequence of all the positive int values starting at 1 and ending at
Integer.MAX_VALUE.static IntSequence positiveFromZero()
IntSequence of all the positive int values starting at 0 and ending at
Integer.MAX_VALUE.static IntSequence increasingFrom(int start)
IntSequence of int values starting at the given value. This sequence never
terminates but will wrap to Integer.MIN_VALUE when passing Integer.MAX_VALUE.static IntSequence negative()
IntSequence of all the negative int values starting at -1 and ending at
Integer.MIN_VALUE.static IntSequence negativeFromZero()
IntSequence of all the negative int values starting at 0 and ending at
Integer.MIN_VALUE.static IntSequence decreasingFrom(int start)
Sequence of int values starting at the given value. This sequence never
terminates but will wrap to Integer.MAX_VALUE when passing Integer.MIN_VALUE.static IntSequence steppingFrom(int start, int step)
Sequence of all the int values starting at the given value and stepping with the given
step. Pass in a negative step to create a decreasing sequence. This sequence never terminates but will wrap when
passing Integer.MAX_VALUE or Integer.MIN_VALUE.static IntSequence range(int start, int end)
Sequence of all the int values between the given start and end positions, inclusive.static IntSequence range(int start, int end, int step)
Sequence of the int values between the given start and end positions, stepping with the
given step. The step must be given as a positive value, even if the range is a decreasing range.java.lang.IllegalArgumentException - if step < 0range(int, int),
steppingFrom(int, int),
increasingFrom(int),
decreasingFrom(int),
positive(),
positiveFromZero(),
negative(),
negativeFromZero()static IntSequence recurse(int seed, java.util.function.IntUnaryOperator op)
IntSequence 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 f(f(seed)) and so on.
The returned IntSequence sequence never terminates naturally.IntSequence sequence produced by recursively applying the given operation to the given seedgenerate(IntSupplier),
endingAt(int),
until(int)static IntSequence generate(java.util.function.IntSupplier supplier)
IntSequence that is generated from the given supplier and thus never terminates.recurse(int, IntUnaryOperator),
endingAt(int),
until(int)default IntSequence until(int terminal)
IntSequence sequence before the given element, with the previous element as the last
element in this IntSequence sequence.default IntSequence endingAt(int terminal)
IntSequence sequence at the given element, including it as the last element in this
IntSequence sequence.default IntSequence until(java.util.function.IntPredicate terminal)
IntSequence sequence before the element that satisfies the given predicate, with the
previous
element as the last element in this IntSequence sequence.default IntSequence endingAt(java.util.function.IntPredicate terminal)
IntSequence sequence at the element that satisfies the given predicate, including the
element as the last element in this IntSequence sequence.default IntSequence map(java.util.function.IntUnaryOperator mapper)
IntSequence sequence to another set of values specified by the given mapper
function.default Sequence<java.lang.Integer> box()
ints in this IntSequence to their boxed Integer counterparts.default <T> Sequence<T> toSequence(java.util.function.IntFunction<T> mapper)
default IntSequence skip(long skip)
ints in this IntSequence.default IntSequence limit(long limit)
ints returned by this IntSequence.default IntSequence append(java.lang.Iterable<java.lang.Integer> iterable)
Integers in the given Iterable to the end of this IntSequence.default IntSequence append(IntIterable that)
default IntSequence append(IntIterator iterator)
ints in the given IntIterator to the end of this IntSequence.
The appended ints will only be available on the first traversal of the resulting IntSequence.
default IntSequence append(java.util.Iterator<java.lang.Integer> iterator)
Integers in the given Iterator to the end of this IntSequence.
The appended
Integers will only be available on the first traversal of the resulting IntSequence.
default IntSequence append(int... ints)
ints to the end of this IntSequence.default IntSequence append(java.util.stream.Stream<java.lang.Integer> stream)
Integers in the given Stream to the end of this IntSequence.
The appended
Integers will only be available on the first traversal of the resulting IntSequence.
Further traversals will result in IllegalStateException being thrown.
default IntSequence append(java.util.stream.IntStream stream)
int values of the given IntStream to the end of this IntSequence.
The appended ints will only be available on the first traversal of the resulting IntSequence.
Further traversals will result in IllegalStateException being thrown.
default IntSequence filter(java.util.function.IntPredicate predicate)
IntSequence, keeping only the elements that match the given
IntPredicate.default IntSequence filterBack(int firstPrevious, IntBiPredicate predicate)
IntSequence to another sequence of ints while peeking at the previous value in the
sequence.
The predicate has access to the previous int and the current int in the iteration. If the current int is the first value in the sequence, and there is no previous value, the provided replacement value is used as the first previous value.
default IntSequence filterForward(int lastNext, IntBiPredicate predicate)
IntSequence to another sequence of ints while peeking at the next int in the sequence.
The predicate has access to the current int and the next int in the iteration. If the current int is the last value in the sequence, and there is no next value, the provided replacement value is used as the last next value.
default <C> C collect(java.util.function.Supplier<? extends C> constructor,
java.util.function.ObjIntConsumer<? super C> adder)
IntSequence into an arbitrary container using the given constructor and adder.default <C> C collectInto(C result,
java.util.function.ObjIntConsumer<? super C> adder)
IntSequence into the given container using the given adder.default java.lang.String join(java.lang.String delimiter)
IntSequence 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)
IntSequence into a string separated by the given delimiter, with the given prefix and suffix.default java.util.OptionalInt reduce(java.util.function.IntBinaryOperator operator)
IntSequence into a single int by iteratively applying the given binary operator to
the current result and each int in the sequence.default int reduce(int identity,
java.util.function.IntBinaryOperator operator)
IntSequence into a single int by iteratively applying the given binary operator to
the current result and each int in the sequence, starting with the given identity as the initial result.default java.util.OptionalInt first()
IntSequence or an empty OptionalInt if there are no
ints in the IntSequence.default java.util.OptionalInt second()
IntSequence or an empty OptionalInt if there are less than two
ints in the IntSequence.default java.util.OptionalInt third()
IntSequence or an empty OptionalInt if there are less than
three ints in the IntSequence.default java.util.OptionalInt last()
IntSequence or an empty OptionalInt if there are no
ints in the IntSequence.default IntSequence step(long step)
IntSequence.default IntSequence distinct()
IntSequence where each item occurs only once, the first time it is encountered.default java.util.OptionalInt min()
IntSequence.default java.util.OptionalInt max()
IntSequence.default long count()
IntSequence.default boolean all(java.util.function.IntPredicate predicate)
IntSequence satisfy the given predicate, false otherwise.default boolean none(java.util.function.IntPredicate predicate)
IntSequence satisfy the given predicate, false otherwise.default boolean any(java.util.function.IntPredicate predicate)
IntSequence satisfy the given predicate, false otherwise.default IntSequence peek(java.util.function.IntConsumer action)
IntConsumer to see each element in this IntSequence as it is traversed.default IntSequence sorted()
IntSequence sorted according to the natural order of the int values.reverse()default int[] toArray()
IntSequence into an array.default IntSequence prefix(int... cs)
IntSequence with the given ints.default IntSequence suffix(int... cs)
IntSequence with the given ints.default IntSequence interleave(IntSequence that)
IntSequence with those of the given IntSequence, stopping when
either sequence finishes.default IntSequence reverse()
IntSequence which iterates over this IntSequence in reverse order.sorted()default IntSequence mapBack(int firstPrevious, java.util.function.IntBinaryOperator mapper)
IntSequence to another sequence of ints while peeking at the previous value in the
sequence.
The mapper has access to the previous int and the current int in the iteration. If the current int is the first value in the sequence, and there is no previous value, the provided replacement value is used as the first previous value.
default IntSequence mapForward(int lastNext, java.util.function.IntBinaryOperator mapper)
IntSequence to another sequence of ints while peeking at the next int in the sequence.
The mapper has access to the current int and the next int in the iteration. If the current int is the last value in the sequence, and there is no next value, the provided replacement value is used as the last next value.
default CharSeq toChars()
default LongSequence toLongs()
default DoubleSequence toDoubles()
default CharSeq toChars(IntToCharFunction mapper)
default LongSequence toLongs(java.util.function.IntToLongFunction mapper)
default DoubleSequence toDoubles(java.util.function.IntToDoubleFunction mapper)
default IntSequence repeat()
The resulting sequence will never terminate if this sequence is non-empty.
default IntSequence repeat(long times)
default Sequence<IntSequence> window(int window)
IntSequence into a sequence of IntSequences of elements, each with
the size of the given window. The first item in each list is the second item in the previous list. The final
IntSequence may be shorter than the window. This is equivalent to window(window, 1).default Sequence<IntSequence> window(int window, int step)
IntSequence into a sequence of IntSequences 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.default Sequence<IntSequence> batch(int size)
IntSequence into a sequence of IntSequences of distinct elements,
each with the given batch size. This is equivalent to window(size, size).default Sequence<IntSequence> batch(IntBiPredicate predicate)
IntSequence into a sequence of IntSequences 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 void removeAll()
Iterator.remove().