T
- the value typepublic abstract class Ix<T>
extends java.lang.Object
implements java.lang.Iterable<T>
All operators tolerate null
elements.
The Iterables have to be run in a single-threaded manner and none of the participating operators expect or support concurrency.
Constructor and Description |
---|
Ix() |
Modifier and Type | Method and Description |
---|---|
Ix<java.lang.Boolean> |
all(IxPredicate<? super T> predicate)
Emits true if all elements of this sequence match a given predicate (including empty).
|
Ix<java.lang.Boolean> |
any(IxPredicate<? super T> predicate)
Emits true if any element of this sequence matches the given predicate,
false otherwise (or for empty sequences).
|
<R> R |
as(IxFunction<? super Ix<T>,R> transformer)
Calls the given transformers with this and returns its value allowing
fluent conversions to non-Ix types.
|
Ix<java.lang.Double> |
averageDouble()
Calculates the double-based average of this sequence of numbers.
|
Ix<java.lang.Float> |
averageFloat()
Calculates the float-based average of this sequence of numbers.
|
Ix<java.util.List<T>> |
buffer(int size)
Buffers the subsequent
size elements into a sequence of
non-overlapping Lists. |
Ix<java.util.List<T>> |
buffer(int size,
int skip)
Buffers the subsequent
size elements into a sequence of
potentially overlapping Lists. |
Ix<java.util.List<T>> |
bufferSplit(IxPredicate<? super T> predicate)
Buffer until an item is encountered for which the predicate returns true,
triggering a new buffer.
|
Ix<java.util.List<T>> |
bufferUntil(IxPredicate<? super T> predicate)
Buffer until an item is encountered after which the predicate returns true
to start a new buffer.
|
Ix<java.util.List<T>> |
bufferWhile(IxPredicate<? super T> predicate)
Buffer while an item is encountered before which the predicate returns false
to start a new buffer.
|
<R> Ix<R> |
cast(java.lang.Class<R> clazz)
Cast the elements to the specified class.
|
static Ix<java.lang.Integer> |
characters(java.lang.CharSequence cs)
Emits all characters from the given CharSequence as integer values.
|
static Ix<java.lang.Integer> |
characters(java.lang.CharSequence cs,
int start,
int end)
Emits a range of characters from the given CharSequence as integer values.
|
protected static <U> U |
checkedCall(java.util.concurrent.Callable<U> callable)
Calls the given callable and rethrows its exception
(as RuntimeException if necessary).
|
<C> Ix<C> |
collect(IxSupplier<C> initialFactory,
IxConsumer2<C,T> collector)
Collect the elements into a collection via collector action and emit that collection
as a single item.
|
Ix<java.lang.Object[]> |
collectToArray()
Collects the elements of this sequence into an Object array.
|
Ix<java.util.List<T>> |
collectToList()
Collects the elements of this sequence into a List.
|
<K> Ix<java.util.Map<K,T>> |
collectToMap(IxFunction<? super T,? extends K> keySelector)
Collects the elements of this sequence into a Map where the key is
determined from each element via the keySelector function; duplicates are
overwritten.
|
<K,V> Ix<java.util.Map<K,V>> |
collectToMap(IxFunction<? super T,? extends K> keySelector,
IxFunction<? super T,? extends V> valueSelector)
Collects the elements of this sequence into a Map where the key is
determined from each element via the keySelector function and
the value is derived from the same element via the valueSelector function; duplicates are
overwritten.
|
<K> Ix<java.util.Map<K,java.util.Collection<T>>> |
collectToMultimap(IxFunction<? super T,? extends K> keySelector)
Collects the elements of this sequence into a multi-Map where the key is
determined from each element via the keySelector function.
|
<K,V> Ix<java.util.Map<K,java.util.Collection<V>>> |
collectToMultimap(IxFunction<? super T,? extends K> keySelector,
IxFunction<? super T,? extends V> valueSelector)
Collects the elements of this sequence into a multi-Map where the key is
determined from each element via the keySelector function and
the value is derived from the same element via the valueSelector function.
|
Ix<java.util.Set<T>> |
collectToSet()
Collects the elements of this sequence into a Set.
|
<R> Ix<R> |
compose(IxFunction<? super Ix<T>,? extends java.lang.Iterable<? extends R>> transformer)
When the iterator() of the returned Ix is called, it calls the transformer function
with this Ix instance and emits the elements of the returned Iterable.
|
static <T> Ix<T> |
concat(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
Concatenates the elements of Iterable sources, provided as an Iterable itself, sequentially.
|
static <T> Ix<T> |
concat(java.lang.Iterable<? extends T> source1,
java.lang.Iterable<? extends T> source2)
Concatenates the elements of two Iterable sources sequentially
The result's iterator() forwards the remove() calls to the current iterator.
|
static <T> Ix<T> |
concat(java.lang.Iterable<? extends T> source1,
java.lang.Iterable<? extends T> source2,
java.lang.Iterable<? extends T> source3)
Concatenates the elements of three Iterable sources sequentially
The result's iterator() forwards the remove() calls to the current iterator.
|
static <T> Ix<T> |
concat(java.lang.Iterable<? extends T> source1,
java.lang.Iterable<? extends T> source2,
java.lang.Iterable<? extends T> source3,
java.lang.Iterable<? extends T> source4)
Concatenates the elements of three Iterable sources sequentially
The result's iterator() forwards the remove() calls to the current iterator.
|
static <T> Ix<T> |
concatArray(java.lang.Iterable<? extends T>... sources)
Concatenates the elements of Iterable sources, provided as an array, sequentially.
|
<R> Ix<R> |
concatMap(IxFunction<? super T,? extends java.lang.Iterable<? extends R>> mapper)
Maps each element from this sequence into subsequent Iterable sequences whose elements are
concatenated in order.
|
Ix<T> |
concatWith(java.lang.Iterable<? extends T> other)
Emits elements of this sequence followed by the elements of the other sequence.
|
Ix<java.lang.Boolean> |
contains(java.lang.Object o)
Emits true if the sequence contains the given Object, compared via null-safe
equals.
|
Ix<java.lang.Integer> |
count()
Emits the number of elements in this sequence.
|
Ix<java.lang.Long> |
countLong()
Emits the number of elements, as a long, in this sequence.
|
Ix<T> |
defaultIfEmpty(T value)
Emits the given value if this sequence is empty, streams this sequence otherwise.
|
static <T> Ix<T> |
defer(IxSupplier<? extends java.lang.Iterable<? extends T>> factory)
Defers the generation of the actual Iterable till the iterator() is called on
the resulting Ix.
|
Ix<T> |
distinct()
Emits only distinct, never before seen elements (according to null-safe equals())
of this sequence.
|
<K> Ix<T> |
distinct(IxFunction<? super T,K> keySelector)
Emits only distinct, never before seen keys extracted from elements
(according to null-safe equals()) of this sequence.
|
Ix<T> |
distinctUntilChanged()
Emits elements from this sequence if each element is different from the previous element
(according to a null-safe equals()), dropping elements that evaluate to the same as the previous.
|
<K> Ix<T> |
distinctUntilChanged(IxFunction<? super T,K> keySelector)
Emits elements from this sequence if each element is different from the previous element
(according to a null-safe equals() of the extracted key), dropping elements that evaluate
to the same as the previous.
|
Ix<T> |
distinctUntilChanged(IxPredicate2<? super T,? super T> comparer)
Emits elements from this sequence if each element is different from the previous element
(according to a comparer), dropping elements that evaluate to the same as the previous.
|
Ix<T> |
doOnCompleted(java.lang.Runnable action)
Calls the given action after consumption of this sequence has completed, i.e., when
hasNext() of this Ix.iterator() returns false.
|
Ix<T> |
doOnNext(IxConsumer<? super T> action)
Calls the given action just before when the consumer calls next() of this Ix.iterator().
|
static <T> Ix<T> |
empty()
No elements are emitted.
|
Ix<T> |
endWith(T... values)
Emits the elements of this sequence followed by the elements of the given array of values.
|
Ix<T> |
every(int nth)
Emit every Nth item only from upstream.
|
Ix<T> |
except(java.lang.Iterable<? extends T> other)
Emits distinct elements from this and the other Iterable which are not
in the other sequence (i.e., (A union B) minus (A intersection B)).
|
Ix<T> |
filter(IxPredicate<T> predicate)
Emits elements of this sequence which match the given predicate only.
|
T |
first()
Returns the first element of this sequence.
|
T |
first(T defaultValue)
Returns the first element of this sequence or the defaultValue
if this sequence is empty.
|
<R> Ix<R> |
flatMap(IxFunction<? super T,? extends java.lang.Iterable<? extends R>> mapper)
Maps each element from this sequence into subsequent Iterable sequences whose elements are
concatenated in order.
|
void |
foreach(IxConsumer<? super T> action)
Consumes the entire sequence and calls the given action with each value.
|
void |
foreachWhile(IxPredicate<? super T> predicate)
Consumes the entire sequence and calls the given predicate with each value;
which can stop the iteration by returning false.
|
static <T,R> Ix<R> |
forloop(T seed,
IxPredicate<? super T> condition,
IxFunction<? super T,? extends T> next,
IxFunction<? super T,? extends R> selector)
Generates a sequence of values via a generic indexed for-loop style construct;
the index starts with the given seed, checked via a condition (to terminate),
generated from the index via the selector and then a new index is generated via next.
|
static <T> Ix<T> |
from(java.lang.Iterable<T> source)
Wraps the given Iterable source into an Ix instance (if
not already an Ix subclass).
|
static <T> Ix<T> |
fromArray(T... values)
Emits all the elements of the given array.
|
static <T> Ix<T> |
fromArrayRange(int start,
int end,
T... values)
Emits a range of elements from the given array.
|
static <T> Ix<T> |
generate(IxConsumer<IxEmitter<T>> nextSupplier)
Calls the given action to generate a value or terminate whenever the next()
is called on the resulting Ix.iterator().
|
static <T,S> Ix<T> |
generate(IxSupplier<S> stateSupplier,
IxFunction2<S,IxEmitter<T>,S> nextSupplier)
Calls the given function (with per-iterator state) to generate a value or terminate
whenever the next() is called on the resulting Ix.iterator().
|
static <T,S> Ix<T> |
generate(IxSupplier<S> stateSupplier,
IxFunction2<S,IxEmitter<T>,S> nextSupplier,
IxConsumer<? super S> stateDisposer)
Calls the given function (with per-iterator state) to generate a value or terminate
whenever the next() is called on the resulting Ix.iterator().
|
<K> Ix<GroupedIx<K,T>> |
groupBy(IxFunction<? super T,? extends K> keySelector)
Groups elements of this sequence into distinct groups keyed by the keys returned by the keySelector.
|
<K,V> Ix<GroupedIx<K,V>> |
groupBy(IxFunction<? super T,? extends K> keySelector,
IxFunction<? super T,? extends V> valueSelector)
Groups mapped elements (by the valueSelector) of this sequence into distinct groups
keyed by the keys returned by the keySelector.
|
Ix<java.lang.Boolean> |
hasElements()
Emits true if this sequence has elements, emits false otherwise.
|
Ix<T> |
hide()
Hides the identity of this Ix instance and prevents certain identity-based optimizations.
|
Ix<T> |
ignoreElements()
Runs through this sequence, ignoring all values until this sequence completes.
|
Ix<T> |
intersect(java.lang.Iterable<? extends T> other)
Emits distinct values of this and the other Iterables that are present in
both sequences.
|
<U extends java.util.Collection<? super T>> |
into(U collection)
Consumes the entire sequence and adds each element into the given collection
that is also returned.
|
Ix<java.lang.String> |
join()
Converts elements of this sequence to String and concatenates them into
a single, comma separated String.
|
Ix<java.lang.String> |
join(java.lang.CharSequence separator)
Converts elements of this sequence to String and concatenates them into
a single String separated by the given character sequence.
|
static <T> Ix<T> |
just(T value)
Emits a single constant value.
|
T |
last()
Returns the last element of this sequence.
|
T |
last(T defaultValue)
Returns the last element of this sequence or the defaultValue if
this sequence is empty.
|
<R> Ix<R> |
lift(IxFunction<? super java.util.Iterator<T>,? extends java.util.Iterator<R>> lifter)
Calls the given lifter function with the iterator of this sequence and emits
elements of the returned Iterator.
|
<R> Ix<R> |
map(IxFunction<? super T,? extends R> mapper)
Maps each element of this sequence to some other value.
|
Ix<T> |
max()
Emits the first maximum element according to their natural order.
|
Ix<T> |
max(java.util.Comparator<? super T> comparator)
Emits the first maximum element according to the given comparator.
|
Ix<java.lang.Integer> |
maxInt()
Returns the first maximum integer value.
|
Ix<java.lang.Long> |
maxLong()
Returns the first maximum long value.
|
static <T> Ix<T> |
merge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
Concatenates the elements of Iterable sources, provided as an Iterable itself, sequentially.
|
static <T> Ix<T> |
mergeArray(java.lang.Iterable<? extends T>... sources)
Concatenates the elements of Iterable sources, provided as an array, sequentially.
|
Ix<T> |
mergeWith(java.lang.Iterable<? extends T> other)
Emits elements of this sequence followed by the elements of the other sequence.
|
Ix<T> |
min()
Emits the first minimum element according to their natural order.
|
Ix<T> |
min(java.util.Comparator<? super T> comparator)
Emits the first minimum element according to the given comparator.
|
Ix<java.lang.Integer> |
minInt()
Returns the first minimum integer value.
|
Ix<java.lang.Long> |
minLong()
Returns the first minimum long value.
|
protected static int |
nonNegative(int n,
java.lang.String name)
Checks if the given value is non-negative and returns it; throws
an IllegalArgumentException otherwise.
|
protected static long |
nonNegative(long n,
java.lang.String name)
Checks if the given value is non-negative and returns it; throws
an IllegalArgumentException otherwise.
|
protected static <U> U |
nullCheck(U value,
java.lang.String message)
Checks if the value is null and if so, throws
a NullPointerException with the given message.
|
Ix<T> |
orderBy()
Orders elements according to their natural order.
|
Ix<T> |
orderBy(java.util.Comparator<? super T> comparator)
Orders elements according to the comparator.
|
<K extends java.lang.Comparable<? super K>> |
orderBy(IxFunction<? super T,K> keySelector)
Orders elements according to the natural order of the extracted keys from these elements.
|
Ix<T> |
orderByReverse()
Orders elements according to their reverse natural order.
|
Ix<T> |
orderByReverse(java.util.Comparator<? super T> comparator)
Orders elements according to the reversed comparator.
|
<K extends java.lang.Comparable<? super K>> |
orderByReverse(IxFunction<? super T,K> keySelector)
Orders elements according to the reverse natural order of the extracted keys from these elements.
|
static <T extends java.lang.Comparable<? super T>> |
orderedMerge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
Merges self-comparable items from an Iterable sequence of Iterable sequences, picking
the smallest item from all those inner Iterables until all sources complete.
|
static <T> Ix<T> |
orderedMerge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources,
java.util.Comparator<? super T> comparator)
Merges items from an Iterable sequence of Iterable sequences, picking
the smallest item (according to a custom comparator) from all those inner
Iterables until all sources complete.
|
static <T> Ix<T> |
orderedMergeArray(java.util.Comparator<? super T> comparator,
java.lang.Iterable<? extends T>... sources)
Merges items from an array of Iterable sequences, picking
the smallest item (according to a custom comparator) from all those inner
Iterables until all sources complete.
|
static <T extends java.lang.Comparable<? super T>> |
orderedMergeArray(java.lang.Iterable<? extends T>... sources)
Merges self-comparable items from an Iterable sequence of Iterable sequences, picking
the smallest item from all those inner Iterables until all sources complete.
|
protected static int |
positive(int n,
java.lang.String name)
Checks if the given value is positive and returns it; throws
an IllegalArgumentException otherwise.
|
void |
print()
Prints the elements of this sequence to the console, separated
by a comma+space and with a line break after roughly 80 characters.
|
void |
print(java.lang.CharSequence separator,
int charsPerLine)
Prints the elements of this sequence to the console, separated
by the given separator and with a line break after roughly the
given charsPerLine amount.
|
void |
println()
Prints each element of this sequence into a new line on the console.
|
void |
println(java.lang.CharSequence prefix)
Prints each element of this sequence into a new line on the console, prefixed
by the given character sequence.
|
Ix<T> |
publish()
Shares an underlying Iterator that is consumed only once and each created iterator() that calls
next() will receive the elements; other iterator() instances may receive different or no elements
at all.
|
<R> Ix<R> |
publish(IxFunction<? super Ix<T>,? extends java.lang.Iterable<? extends R>> transform)
Shares an Iterator, exposed as an Ix sequence, for the duration of the transform function called
for each iterator() invocation and emits elements of the resulting iterable sequence of the function.
|
static Ix<java.lang.Integer> |
range(int start,
int count)
Emits a range of incrementing integer values, starting from
start and
up to count times. |
Ix<T> |
readOnly()
Prevents the downstream from calling remove() and throws
an UnsupportedOperationException instead.
|
Ix<T> |
readOnly(boolean silent)
Prevents the downstream from calling remove() by optionally
ignoring it or throwing an UnsupportedOperationException.
|
Ix<T> |
reduce(IxFunction2<T,T,T> reducer)
Reduces the elements of this sequence into a single value via a reducer function.
|
<C> Ix<C> |
reduce(IxSupplier<C> initialFactory,
IxFunction2<C,T,C> reducer)
Given a per-iterator() initial value, reduces the elements of this sequence into a single
value via a reducer function.
|
Ix<T> |
remove(IxPredicate<? super T> predicate)
Removes those elements via Iterator.remove() from this sequence that match the
given predicate.
|
void |
removeAll()
Removes all elements by repeatedly calling this sequence's Iterator.remove().
|
void |
removeAll(IxPredicate<? super T> predicate)
Consumes this Iterable and removes all elements for
which the predicate returns true; in other words,
remove those elements of a mutable source that match
the predicate.
|
Ix<T> |
repeat()
Repeats this sequence indefinitely.
|
Ix<T> |
repeat(IxBooleanSupplier stopPredicate)
Repeats this sequence if the given predicate returns true after the sequence
completes in a round.
|
Ix<T> |
repeat(long times)
Repeats this sequence at most the given number of times.
|
Ix<T> |
repeat(long times,
IxBooleanSupplier stopPredicate)
Repeats this sequence if the given predicate returns true after the sequence
completes in a round or at most the given number of times.
|
static <T> Ix<T> |
repeatCallable(java.util.concurrent.Callable<T> callable)
Repeatedly calls the given callable indefinitely and
emits the returned value.
|
static <T> Ix<T> |
repeatValue(T value)
Repeats the given value indefinitely.
|
static <T> Ix<T> |
repeatValue(T value,
IxBooleanSupplier stopPredicate)
Repeats the given value until the given predicate returns true.
|
static <T> Ix<T> |
repeatValue(T value,
long count)
Repeats the given value at most count times.
|
static <T> Ix<T> |
repeatValue(T value,
long count,
IxBooleanSupplier stopPredicate)
Repeats the given value at most count times or until the given predicate returns true.
|
Ix<T> |
replay()
Caches and replays all elements of this sequence to consumers of this' iterator().
|
Ix<T> |
replay(int size)
Caches and replays the last
size elements of this sequence to consumers of this' iterator(). |
<R> Ix<R> |
replay(int size,
IxFunction<? super Ix<T>,? extends java.lang.Iterable<? extends R>> transform)
Caches and replays the the last
size elements of this sequence for the duration of the given transform function
without consuming this sequence multiple times. |
<R> Ix<R> |
replay(IxFunction<? super Ix<T>,? extends java.lang.Iterable<? extends R>> transform)
Caches and replays the elements of this sequence for the duration of the given transform function
without consuming this sequence multiple times.
|
Ix<T> |
retain(IxPredicate<? super T> predicate)
Removes those elements via Iterator.remove() from this sequence that don't match the
given predicate.
|
void |
retainAll(IxPredicate<? super T> predicate)
Consumes this Iterable and removes all elements for
which the predicate returns false; in other words,
retain those elements of a mutable source that match
the predicate.
|
Ix<T> |
reverse()
Plays this sequence in reverse.
|
void |
run()
Iterates over this instance, dropping all values it produces.
|
Ix<T> |
scan(IxFunction2<T,T,T> scanner)
Performs a running accumulation, that is, returns intermediate elements returned by the
scanner function.
|
<R> Ix<R> |
scan(IxSupplier<R> initialFactory,
IxFunction2<R,T,R> scanner)
Performs a running accumulation, that is, returns intermediate elements returned by the
scanner function, starting with a per-iterator initial value.
|
Ix<java.lang.Boolean> |
sequenceEqual(java.lang.Iterable<? extends T> other)
Determines if two sequences have the same elements in the same order and are the same length based
on null-safe object equality.
|
Ix<java.lang.Boolean> |
sequenceEqual(java.lang.Iterable<? extends T> other,
IxPredicate2<? super T,? super T> comparer)
Determines if two sequences have the same elements in the same order and are the same length based
on the given comparer's boolean value.
|
T |
single()
Returns the single element of this sequence or throws a NoSuchElementException
if this sequence is empty or IndexOutOfBoundsException if this sequence has more
than on element
|
T |
single(T defaultValue)
Returns the single element of this sequence, defaultValue
if this sequence is empty or IndexOutOfBoundsException if this sequence has more
than one element
|
Ix<T> |
skip(int n)
Skips the first n elements from this sequence.
|
Ix<T> |
skipLast(int n)
Skips the last n elements from this sequence.
|
Ix<T> |
skipWhile(IxPredicate<? super T> predicate)
Skips the first elements while the given predicate returns true; once it returns false
all subsequent elements are emitted.
|
static Ix<java.lang.String> |
split(java.lang.String string,
java.lang.String by)
Emits a sequence of substring of a string split by the given separator.
|
Ix<T> |
startWith(T... values)
Emits elements of the given array followed by the elements of this sequence.
|
void |
subscribe()
Iterates over this instance, dropping all values it produces.
|
void |
subscribe(IxConsumer<? super T> onNext)
Iterates over this sequence and calls the given onNext action with
each element.
|
void |
subscribe(IxConsumer<? super T> onNext,
IxConsumer<java.lang.Throwable> onError)
Iterates over this sequence and calls the given onNext action with
each element and calls the onError with any exception thrown by the iteration
or the onNext action.
|
void |
subscribe(IxConsumer<? super T> onNext,
IxConsumer<java.lang.Throwable> onError,
java.lang.Runnable onCompleted)
Iterates over this sequence and calls the given onNext action with
each element and calls the onError with any exception thrown by the iteration
or the onNext action; otherwise calls the onCompleted action when the sequence completes
without exception.
|
Ix<java.lang.Integer> |
sumInt()
Sums values of this sequence as integer.
|
Ix<java.lang.Long> |
sumLong()
Sums values of this sequence as long.
|
Ix<T> |
switchIfEmpty(java.lang.Iterable<? extends T> other)
Emits the elements of the other sequence if this sequence is empty.
|
Ix<T> |
take(int n)
Emits the first n elements (or less) of this sequence.
|
Ix<T> |
takeLast(int n)
Emits the last n elements (or fewer) of this sequence.
|
Ix<T> |
takeUntil(IxPredicate<? super T> stopPredicate)
Take elements from this sequence until the given predicate returns true
for the current element (checked after emission of that element).
|
Ix<T> |
takeWhile(IxPredicate<? super T> predicate)
Take elements from this sequence while the given predicate returns true
for the current element (checked before emission of that element).
|
java.lang.Object[] |
toArray()
Collects the elements of this sequence into an Object array.
|
<U> U[] |
toArray(U[] array)
Collects the elements of this sequence into a generic array provided.
|
java.util.List<T> |
toList()
Collects the elements of this sequence into a List.
|
Ix<java.lang.Long> |
toLong()
Maps this sequence of numbers into a sequence of longs.
|
<K> java.util.Map<K,T> |
toMap(IxFunction<? super T,? extends K> keySelector)
Collects the elements of this sequence into a Map where the key is
determined from each element via the keySelector function; duplicates are
overwritten.
|
<K,V> java.util.Map<K,V> |
toMap(IxFunction<? super T,? extends K> keySelector,
IxFunction<? super T,? extends V> valueSelector)
Collects the elements of this sequence into a Map where the key is
determined from each element via the keySelector function and
the value is derived from the same element via the valueSelector function; duplicates are
overwritten.
|
<K> java.util.Map<K,java.util.Collection<T>> |
toMultimap(IxFunction<? super T,? extends K> keySelector)
Collects the elements of this sequence into a multi-Map where the key is
determined from each element via the keySelector function.
|
<K,V> java.util.Map<K,java.util.Collection<V>> |
toMultimap(IxFunction<? super T,? extends K> keySelector,
IxFunction<? super T,? extends V> valueSelector)
Collects the elements of this sequence into a multi-Map where the key is
determined from each element via the keySelector function and
the value is derived from the same element via the valueSelector function.
|
java.util.Set<T> |
toSet()
Collects the elements of this sequence into a Set.
|
<R> Ix<R> |
transform(IxTransform<T,R> transformer)
Allows working with the Iterator of this sequence and emit elements in
a more flexible way
The result's iterator() doesn't support remove().
|
Ix<T> |
union(java.lang.Iterable<? extends T> other)
Emits a distinct set of values from both this and the other sequence.
|
Ix<Ix<T>> |
window(int size)
Emits inner Ix Iterables of non-overlapping sequences mapped from this sequence
with the given maximum size each.
|
Ix<Ix<T>> |
window(int size,
int skip)
Emits inner Ix Iterables of potentially overlapping sequences mapped from this
sequence with the given maximum size each and started each
skip source elements. |
static <T,R> Ix<R> |
zip(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources,
IxFunction<? super java.lang.Object[],R> zipper)
Combines the next element from each source Iterable, provided as an Iterable itself,
via a zipper function.
|
static <T,R> Ix<R> |
zip(java.lang.Iterable<? extends T>[] sources,
IxFunction<? super java.lang.Object[],R> zipper)
Combines the next element from each source Iterable via a zipper function.
|
static <T1,T2,T3,T4,R> |
zip(java.lang.Iterable<T1> source1,
java.lang.Iterable<T2> source2,
java.lang.Iterable<T3> source3,
java.lang.Iterable<T4> source4,
IxFunction4<? super T1,? super T2,? super T3,? super T4,? extends R> zipper)
Combines the next element from each source Iterable via a zipper function.
|
static <T1,T2,T3,R> |
zip(java.lang.Iterable<T1> source1,
java.lang.Iterable<T2> source2,
java.lang.Iterable<T3> source3,
IxFunction3<? super T1,? super T2,? super T3,? extends R> zipper)
Combines the next element from each source Iterable via a zipper function.
|
static <T1,T2,R> Ix<R> |
zip(java.lang.Iterable<T1> source1,
java.lang.Iterable<T2> source2,
IxFunction2<? super T1,? super T2,? extends R> zipper)
Combines the next element from each source Iterable via a zipper function.
|
<U,R> Ix<R> |
zipWith(java.lang.Iterable<U> other,
IxFunction2<? super T,? super U,? extends R> zipper)
Combines the next element from this and the other source Iterable via a zipper function.
|
public static Ix<java.lang.Integer> characters(java.lang.CharSequence cs)
The result's iterator() doesn't support remove().
cs
- the source character sequence, not nulljava.lang.NullPointerException
- if cs is nullpublic static Ix<java.lang.Integer> characters(java.lang.CharSequence cs, int start, int end)
The result's iterator() doesn't support remove().
cs
- the source character sequence, not nullstart
- the start character index, inclusive, non-negativeend
- the end character index, exclusive, non-negativejava.lang.NullPointerException
- if cs is nulljava.lang.IndexOutOfBoundsException
- if start is out of range [0, cs.length]public static <T> Ix<T> concat(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
The result's iterator() forwards the remove() calls to the current iterator.
Note that merge and concat operations are the same in the Iterable world.
T
- the common base typesources
- the Iterable sequence of source Iterablesjava.lang.NullPointerException
- if sources is nullmerge(Iterable)
public static <T> Ix<T> concat(java.lang.Iterable<? extends T> source1, java.lang.Iterable<? extends T> source2)
The result's iterator() forwards the remove() calls to the current iterator.
Note that merge and concat operations are the same in the Iterable world.
T
- the value typesource1
- the first source, not nullsource2
- the second source, not nulljava.lang.NullPointerException
- if any of the sources is nullpublic static <T> Ix<T> concat(java.lang.Iterable<? extends T> source1, java.lang.Iterable<? extends T> source2, java.lang.Iterable<? extends T> source3)
The result's iterator() forwards the remove() calls to the current iterator.
Note that merge and concat operations are the same in the Iterable world.
T
- the value typesource1
- the first source, not nullsource2
- the second source, not nullsource3
- the third source, not nulljava.lang.NullPointerException
- if any of the sources is nullpublic static <T> Ix<T> concat(java.lang.Iterable<? extends T> source1, java.lang.Iterable<? extends T> source2, java.lang.Iterable<? extends T> source3, java.lang.Iterable<? extends T> source4)
The result's iterator() forwards the remove() calls to the current iterator.
Note that merge and concat operations are the same in the Iterable world.
T
- the value typesource1
- the first source, not nullsource2
- the second source, not nullsource3
- the third source, not nullsource4
- the fourth source, not nulljava.lang.NullPointerException
- if any of the sources is nullpublic static <T> Ix<T> concatArray(java.lang.Iterable<? extends T>... sources)
The result's iterator() forwards the remove() calls to the current iterator.
Note that merge and concat operations are the same in the Iterable world.
T
- the common base typesources
- the array of source Iterablesjava.lang.NullPointerException
- if sources is nullmergeArray(Iterable...)
public static <T> Ix<T> defer(IxSupplier<? extends java.lang.Iterable<? extends T>> factory)
The result's iterator() forwards the remove() calls to the generated Iterable's Iterator.
T
- the value typefactory
- the function that returns an Iterable when the resulting Ix.iterator() is calledjava.lang.NullPointerException
- if factory is nullpublic static <T> Ix<T> empty()
The result's iterator() doesn't support remove().
T
- the value typepublic static <T> Ix<T> from(java.lang.Iterable<T> source)
The result's iterator() forwards the remove() calls to the source's iterator().
T
- the value typesource
- the Iterable to wrap, not nulljava.lang.NullPointerException
- if source is nullpublic static <T> Ix<T> fromArray(T... values)
The result's iterator() doesn't support remove().
T
- the value typevalues
- the array of values, not nulljava.lang.NullPointerException
- if values is nullpublic static <T> Ix<T> fromArrayRange(int start, int end, T... values)
The result's iterator() doesn't support remove().
T
- the value typestart
- the staring index, inclusive, non-negativeend
- the end index, exclusive, non-negativevalues
- the array of valuesjava.lang.NullPointerException
- if values is nulljava.lang.IndexOutOfBoundsException
- if either start or end are not in [0, values.length]public static <T,R> Ix<R> forloop(T seed, IxPredicate<? super T> condition, IxFunction<? super T,? extends T> next, IxFunction<? super T,? extends R> selector)
The result's iterator() doesn't support remove().
T
- the index value typeR
- the result value typeseed
- the initial value of the indexcondition
- the receives the current index (before selector is called) and if it
returns false, the sequence terminatesnext
- the function that receives the current index and returns the next indexselector
- the function that receives the current index and returns the value
to be emitted.java.lang.NullPointerException
- if condition, next or selector is nullpublic static <T> Ix<T> generate(IxConsumer<IxEmitter<T>> nextSupplier)
The result's iterator() doesn't support remove().
The action may call onNext
at most once to signal the next value per action invocation.
The onCompleted
should be called to indicate no further values will be generated (may be
called with an onNext in the same action invocation). Calling onError
will immediately
throw the given exception (as is if it's a RuntimeException or Error; or wrapped into a RuntimeException).
T
- the value typenextSupplier
- the action called with an IxEmitter API to receive value, not nulljava.lang.NullPointerException
- if nextSupplier is nullpublic static <T,S> Ix<T> generate(IxSupplier<S> stateSupplier, IxFunction2<S,IxEmitter<T>,S> nextSupplier)
The result's iterator() doesn't support remove().
The action may call onNext
at most once to signal the next value per action invocation.
The onCompleted
should be called to indicate no further values will be generated (may be
called with an onNext in the same action invocation). Calling onError
will immediately
throw the given exception (as is if it's a RuntimeException or Error; or wrapped into a RuntimeException).
T
- the value typeS
- the state type supplied to and returned by the nextSupplier functionstateSupplier
- the function that returns a state for each invocation of iterator()nextSupplier
- the action called with an IxEmitter API to receive value, not nulljava.lang.NullPointerException
- if stateSupplier or nextSupplier is nullpublic static <T,S> Ix<T> generate(IxSupplier<S> stateSupplier, IxFunction2<S,IxEmitter<T>,S> nextSupplier, IxConsumer<? super S> stateDisposer)
The result's iterator() doesn't support remove().
The action may call onNext
at most once to signal the next value per action invocation.
The onCompleted
should be called to indicate no further values will be generated (may be
called with an onNext in the same action invocation). Calling onError
will immediately
throw the given exception (as is if it's a RuntimeException or Error; or wrapped into a RuntimeException).
Note that since there is no direct way to cancel an Iterator, the stateDisposer is only invoked when the nextSupplier calls a terminal method.
T
- the value typeS
- the state type supplied to and returned by the nextSupplier functionstateSupplier
- the function that returns a state for each invocation of iterator()nextSupplier
- the action called with an IxEmitter API to receive value, not nullstateDisposer
- the action called when the nextSupplier signals an onError
or onCompleted
.java.lang.NullPointerException
- if stateSupplier, nextSupplier or stateDisposer is nullpublic static <T> Ix<T> just(T value)
The result's iterator() doesn't support remove().
T
- the value typevalue
- the constant value to emitpublic static <T> Ix<T> merge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
The result's iterator() forwards the remove() calls to the current iterator.
Note that merge and concat operations are the same in the Iterable world.
T
- the common base typesources
- the Iterable sequence of source Iterablesjava.lang.NullPointerException
- if sources is nullconcat(Iterable)
public static <T> Ix<T> mergeArray(java.lang.Iterable<? extends T>... sources)
The result's iterator() forwards the remove() calls to the current iterator.
Note that merge and concat operations are the same in the Iterable world.
T
- the common base typesources
- the array of source Iterablesjava.lang.NullPointerException
- if sources is nullconcatArray(Iterable...)
public static <T extends java.lang.Comparable<? super T>> Ix<T> orderedMerge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
T
- the value typesources
- the Iterable sequence of Iterables of self-comparable itemspublic static <T> Ix<T> orderedMerge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources, java.util.Comparator<? super T> comparator)
T
- the value typesources
- the Iterable sequence of Iterablescomparator
- the comparator to compare items and pick the one that returns negative will be pickedpublic static <T extends java.lang.Comparable<? super T>> Ix<T> orderedMergeArray(java.lang.Iterable<? extends T>... sources)
T
- the value typesources
- the Iterable sequence of Iterables of self-comparable itemspublic static <T> Ix<T> orderedMergeArray(java.util.Comparator<? super T> comparator, java.lang.Iterable<? extends T>... sources)
T
- the value typesources
- the Iterable sequence of Iterablescomparator
- the comparator to compare items and pick the one that returns negative will be pickedpublic static Ix<java.lang.Integer> range(int start, int count)
start
and
up to count
times.start
- the starting valuecount
- the number of integers to emit, non-negativejava.lang.IllegalArgumentException
- if count is negativepublic final Ix<T> readOnly()
readOnly(boolean)
public final Ix<T> readOnly(boolean silent)
silent
- if true, remove() calls are ignored; if false,
remove() calls throw an UnsupportedOperationExceptionpublic static <T> Ix<T> repeatCallable(java.util.concurrent.Callable<T> callable)
The result's iterator() doesn't support remove().
T
- the value typecallable
- the callable to callpublic static <T> Ix<T> repeatValue(T value)
The result's iterator() doesn't support remove().
T
- the value typevalue
- the value to emit whenever next() is calledpublic static <T> Ix<T> repeatValue(T value, long count)
A count of zero will yield an empty sequence, a count of one will yield a sequence with only one element and so forth.
The result's iterator() doesn't support remove().
T
- the value typevalue
- the value to emitcount
- the number of times to emit the value, non-negativejava.lang.IllegalArgumentException
- if count is negativepublic static <T> Ix<T> repeatValue(T value, IxBooleanSupplier stopPredicate)
A count of zero will yield an empty sequence, a count of one will yield a sequence with only one element and so forth.
The result's iterator() doesn't support remove().
T
- the value typevalue
- the value to emitstopPredicate
- the predicate called before any emission; returning
false keeps repeating the value, returning true terminates the sequencejava.lang.NullPointerException
- if stopPredicate is nullpublic static <T> Ix<T> repeatValue(T value, long count, IxBooleanSupplier stopPredicate)
A count of zero will yield an empty sequence, a count of one will yield a sequence with only one element and so forth.
The result's iterator() doesn't support remove().
T
- the value typevalue
- the value to emitcount
- the number of times to emit the value, non-negativestopPredicate
- the predicate called before any emission; returning
false keeps repeating the value, returning true terminates the sequencejava.lang.IllegalArgumentException
- if count is negativejava.lang.NullPointerException
- if stopPredicate is nullpublic static Ix<java.lang.String> split(java.lang.String string, java.lang.String by)
The result's iterator() doesn't support remove().
string
- the string to split, not nullby
- the separator to split along, not nulljava.lang.NullPointerException
- if string or by is nullpublic static <T,R> Ix<R> zip(java.lang.Iterable<? extends T>[] sources, IxFunction<? super java.lang.Object[],R> zipper)
If one of the source Iterables is sorter the sequence terminates eagerly.
The result's iterator() doesn't support remove().
T
- the common element type of the sourcesR
- the result value typesources
- the array of Iterable sources, not nullzipper
- the function that takes an array of values and returns a value
to be emitted, one from each source, not nulljava.lang.NullPointerException
- if sources or zipper is nullpublic static <T,R> Ix<R> zip(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources, IxFunction<? super java.lang.Object[],R> zipper)
If one of the source Iterables is sorter the sequence terminates eagerly.
The result's iterator() doesn't support remove().
T
- the common element type of the sourcesR
- the result value typesources
- the Iterable of Iterable sources, not nullzipper
- the function that takes an array of values and returns a value
to be emitted, one from each source, not nulljava.lang.NullPointerException
- if sources or zipper is nullpublic static <T1,T2,R> Ix<R> zip(java.lang.Iterable<T1> source1, java.lang.Iterable<T2> source2, IxFunction2<? super T1,? super T2,? extends R> zipper)
If one of the source Iterables is sorter the sequence terminates eagerly.
The result's iterator() doesn't support remove().
T1
- the first source's element typeT2
- the second source's element typeR
- the result value typesource1
- the first source Iterablesource2
- the second source Iterablezipper
- the function that takes one from each source, not nulljava.lang.NullPointerException
- if any of the sources or zipper is nullpublic static <T1,T2,T3,R> Ix<R> zip(java.lang.Iterable<T1> source1, java.lang.Iterable<T2> source2, java.lang.Iterable<T3> source3, IxFunction3<? super T1,? super T2,? super T3,? extends R> zipper)
If one of the source Iterables is sorter the sequence terminates eagerly.
The result's iterator() doesn't support remove().
T1
- the first source's element typeT2
- the second source's element typeT3
- the third source's element typeR
- the result value typesource1
- the first source Iterablesource2
- the second source Iterablesource3
- the third source Iterablezipper
- the function that takes one from each source, not nulljava.lang.NullPointerException
- if any of the sources or zipper is nullpublic static <T1,T2,T3,T4,R> Ix<R> zip(java.lang.Iterable<T1> source1, java.lang.Iterable<T2> source2, java.lang.Iterable<T3> source3, java.lang.Iterable<T4> source4, IxFunction4<? super T1,? super T2,? super T3,? super T4,? extends R> zipper)
If one of the source Iterables is sorter the sequence terminates eagerly.
The result's iterator() doesn't support remove().
T1
- the first source's element typeT2
- the second source's element typeT3
- the third source's element typeT4
- the fourth source's element typeR
- the result value typesource1
- the first source Iterablesource2
- the second source Iterablesource3
- the third source Iterablesource4
- the fourth source Iterablezipper
- the function that takes one from each source, not nulljava.lang.NullPointerException
- if any of the sources or zipper is nullpublic final Ix<java.lang.Boolean> all(IxPredicate<? super T> predicate)
The result's iterator() doesn't support remove().
predicate
- the predicate receiving each elementjava.lang.NullPointerException
- if predicate is nullpublic final Ix<java.lang.Boolean> any(IxPredicate<? super T> predicate)
The result's iterator() doesn't support remove().
predicate
- the predicate receiving each elementjava.lang.NullPointerException
- if predicate is nullpublic final <R> R as(IxFunction<? super Ix<T>,R> transformer)
R
- the result typetransformer
- the function receiving this Ix instance and returns a valuejava.lang.NullPointerException
- if transformer is nullpublic final Ix<java.lang.Float> averageFloat()
The returned sequence is empty if this sequence is empty.
This operator force-casts this sequence which may lead to ClassCastException if any of this sequence's elements is not a subclass of Number.
The result's iterator() doesn't support remove().
public final Ix<java.lang.Double> averageDouble()
The returned sequence is empty if this sequence is empty.
This operator force-casts this sequence which may lead to ClassCastException if any of this sequence's elements is not a subclass of Number.
The result's iterator() doesn't support remove().
public final Ix<java.util.List<T>> buffer(int size)
size
elements into a sequence of
non-overlapping Lists.
The result's iterator() doesn't support remove().
size
- the number of elements to group together, positivejava.lang.IllegalArgumentException
- if size is non-positivepublic final Ix<java.util.List<T>> buffer(int size, int skip)
size
elements into a sequence of
potentially overlapping Lists.
The result's iterator() doesn't support remove().
size
- the number of elements to group together, positiveskip
- specifies how often to start a new listjava.lang.IllegalArgumentException
- if size or skip is non-positivepublic final Ix<java.util.List<T>> bufferSplit(IxPredicate<? super T> predicate)
Neither the previous nor the next buffer will contain the item that caused the split
predicate
- the predicate called with each item and should return false
to trigger a new bufferbufferUntil(IxPredicate)
,
bufferWhile(IxPredicate)
public final Ix<java.util.List<T>> bufferUntil(IxPredicate<? super T> predicate)
The item will be part of the previous buffer.
predicate
- the predicate called with each item after the item
has been added to the current buffer and should return true to start a new bufferbufferSplit(IxPredicate)
,
bufferWhile(IxPredicate)
public final Ix<java.util.List<T>> bufferWhile(IxPredicate<? super T> predicate)
The item will be part of the next buffer
predicate
- the predicate called with each item after the item
has been added to the current buffer and should return true to start a new bufferbufferSplit(IxPredicate)
,
bufferUntil(IxPredicate)
public final <R> Ix<R> cast(java.lang.Class<R> clazz)
Note that this is a forced cast on this Ix instance and if not compatible, a ClassCastException might be thrown downstream.
R
- the target typeclazz
- the type token to capture the target typepublic final <C> Ix<C> collect(IxSupplier<C> initialFactory, IxConsumer2<C,T> collector)
The result's iterator() doesn't support remove().
C
- the collection typeinitialFactory
- the function returning a collection for each iterator() callcollector
- the action called with the collection and the current itemjava.lang.NullPointerException
- if initialFactory or collector is nullpublic final Ix<java.lang.Object[]> collectToArray()
The result's iterator() doesn't support remove().
public final Ix<java.util.List<T>> collectToList()
The result's iterator() doesn't support remove().
public final <K> Ix<java.util.Map<K,T>> collectToMap(IxFunction<? super T,? extends K> keySelector)
The result's iterator() doesn't support remove().
K
- the key typekeySelector
- the function that receives the current element and returns
a key for it to be used as the Map key.java.lang.NullPointerException
- if keySelector is nullpublic final <K,V> Ix<java.util.Map<K,V>> collectToMap(IxFunction<? super T,? extends K> keySelector, IxFunction<? super T,? extends V> valueSelector)
The result's iterator() doesn't support remove().
K
- the key typeV
- the value typekeySelector
- the function that receives the current element and returns
a key for it to be used as the Map key.valueSelector
- the function that receives the current element and returns
a value for it to be used as the Map valuejava.lang.NullPointerException
- if keySelector or valueSelector is nullpublic final <K> Ix<java.util.Map<K,java.util.Collection<T>>> collectToMultimap(IxFunction<? super T,? extends K> keySelector)
The result's iterator() doesn't support remove().
K
- the key typekeySelector
- the function that receives the current element and returns
a key for it to be used as the Map key.java.lang.NullPointerException
- if keySelector is nullpublic final <K,V> Ix<java.util.Map<K,java.util.Collection<V>>> collectToMultimap(IxFunction<? super T,? extends K> keySelector, IxFunction<? super T,? extends V> valueSelector)
The result's iterator() doesn't support remove().
K
- the key typeV
- the value typekeySelector
- the function that receives the current element and returns
a key for it to be used as the Map key.valueSelector
- the function that receives the current element and returns
a value for it to be used as the Map valuejava.lang.NullPointerException
- if keySelector or valueSelector is nullpublic final Ix<java.util.Set<T>> collectToSet()
The result's iterator() doesn't support remove().
public final <R> Ix<R> compose(IxFunction<? super Ix<T>,? extends java.lang.Iterable<? extends R>> transformer)
The result's iterator() forwards the call remove() to the returned Iterable's Iterator.
R
- the result value typetransformer
- the transformer called with this Ix when Ix.iterator() is invokedjava.lang.NullPointerException
- if transformer is nullpublic final <R> Ix<R> concatMap(IxFunction<? super T,? extends java.lang.Iterable<? extends R>> mapper)
Note that flatMap and concatMap operations are the same in the Iterable world.
The result's iterator() forwards the call remove() to the current inner Iterator.
R
- the result value typemapper
- the functionjava.lang.NullPointerException
- if mapper is nullflatMap(IxFunction)
public final Ix<T> concatWith(java.lang.Iterable<? extends T> other)
Note that mergeWith and concatWith operations are the same in the Iterable world.
The result's iterator() forwards the call remove() to the current Iterator.
other
- the other sequence to emits elements ofjava.lang.NullPointerException
- if other is nullmergeWith(Iterable)
public final Ix<java.lang.Boolean> contains(java.lang.Object o)
The result's iterator() doesn't support remove().
o
- the value to findpublic final Ix<java.lang.Integer> count()
The result's iterator() doesn't support remove().
public final Ix<java.lang.Long> countLong()
The result's iterator() doesn't support remove().
public final Ix<T> defaultIfEmpty(T value)
The result's iterator() doesn't support remove().
value
- the value to emit if this sequence is emptypublic final Ix<T> distinct()
Note that this operator uses a memory of seen elements which may grow unbounded with long sequences.
The result's iterator() doesn't support remove().
public final <K> Ix<T> distinct(IxFunction<? super T,K> keySelector)
Note that this operator uses a memory of seen elements which may grow unbounded with long sequences.
The result's iterator() doesn't support remove().
K
- the key typekeySelector
- the function taking the current element and returning a key object
that will be compared with null-safe equals().java.lang.NullPointerException
- if keySelector is nullpublic final Ix<T> distinctUntilChanged()
The result's iterator() doesn't support remove().
public final Ix<T> distinctUntilChanged(IxPredicate2<? super T,? super T> comparer)
The result's iterator() doesn't support remove().
comparer
- the predicate receiving the previous element and the current element and
returns true if they are the same (thus ignoring the latter).java.lang.NullPointerException
- if comparer is nullpublic final <K> Ix<T> distinctUntilChanged(IxFunction<? super T,K> keySelector)
The result's iterator() doesn't support remove().
K
- the key typekeySelector
- the function that receives the current element and returns a key that will be compared
via null-safe equals with the previous element's keyjava.lang.NullPointerException
- if comparer is nullpublic final Ix<T> doOnNext(IxConsumer<? super T> action)
The result's iterator() forwards calls to remove() to this Iterator.
action
- the action to call for each itemjava.lang.NullPointerException
- if action is nullpublic final Ix<T> doOnCompleted(java.lang.Runnable action)
The result's iterator() forwards calls to remove() to this' Iterator.
action
- the action to call after the source sequence completesjava.lang.NullPointerException
- if action is nullpublic final Ix<T> endWith(T... values)
The result's iterator() doesn't support remove().
values
- the elements to emit after this sequencejava.lang.NullPointerException
- if values is nullpublic final Ix<T> every(int nth)
Example: Ix.range(1, 5).every(2) will yield {2, 4}.
nth
- how many items to skip + 1public final Ix<T> except(java.lang.Iterable<? extends T> other)
The result's iterator() doesn't support remove().
other
- the other Iterable sequence, not nulljava.lang.NullPointerException
- if other is nullunion(Iterable)
,
intersect(Iterable)
public final Ix<T> filter(IxPredicate<T> predicate)
The result's iterator() forwards the call to remove() to this' Iterator.
predicate
- the predicate receiving the current element and if it
returns true, the value is emitted, ignored otherwise.java.lang.NullPointerException
- if predicate is nullpublic final <R> Ix<R> flatMap(IxFunction<? super T,? extends java.lang.Iterable<? extends R>> mapper)
Note that flatMap and concatMap operations are the same in the Iterable world.
The result's iterator() forwards the call remove() to the current inner Iterator.
R
- the result value typemapper
- the functionjava.lang.NullPointerException
- if mapper is nullconcatMap(IxFunction)
public final <K> Ix<GroupedIx<K,T>> groupBy(IxFunction<? super T,? extends K> keySelector)
The operator doesn't lose data and calling hasNext/next on either the returned Ix or on the inner GroupedIx can move the source sequence forward.
The result's iterator() and the inner groups' Iterators don't support remove().
K
- the key typekeySelector
- the function receiving the current element and returns the key to be used for
grouping the values into the same inner GroupedIx.java.lang.NullPointerException
- if keySelector is nullgroupBy(IxFunction, IxFunction)
public final <K,V> Ix<GroupedIx<K,V>> groupBy(IxFunction<? super T,? extends K> keySelector, IxFunction<? super T,? extends V> valueSelector)
The operator doesn't lose data and calling hasNext/next on either the returned Ix or on the inner GroupedIx can move the source sequence forward.
The result's iterator() and the inner groups' Iterators don't support remove().
K
- the key typeV
- the value typekeySelector
- the function receiving the current element and returns the key to be used for
grouping the values into the same inner GroupedIx.valueSelector
- the function receiving the current element and returns the value to be emitted
by the appropriate groupjava.lang.NullPointerException
- if keySelector or valueSelector is nullgroupBy(IxFunction, IxFunction)
public final Ix<java.lang.Boolean> hasElements()
The result's iterator() doesn't support remove().
public final Ix<T> hide()
The result's iterator() forwards the remove() calls to this' Iterator.
public final Ix<T> intersect(java.lang.Iterable<? extends T> other)
The result's iterator() doesn't support remove().
other
- the other Iterable sequencejava.lang.NullPointerException
- if other is nullexcept(Iterable)
,
union(Iterable)
public final Ix<T> ignoreElements()
The result's iterator() doesn't support remove().
public final Ix<java.lang.String> join()
The result's iterator() doesn't support remove().
public final Ix<java.lang.String> join(java.lang.CharSequence separator)
The result's iterator() doesn't support remove().
separator
- the character sequence separating elementspublic final <R> Ix<R> lift(IxFunction<? super java.util.Iterator<T>,? extends java.util.Iterator<R>> lifter)
The result's iterator() forwards the remove() calls to the returned Iterator.
R
- the result value typelifter
- the function that receives the Iterator of this and returns an Iterator
that will be consumed further onjava.lang.NullPointerException
- if lifter is nullpublic final <R> Ix<R> map(IxFunction<? super T,? extends R> mapper)
The result's iterator() forwards the remove() calls to this' Iterator.
R
- the result value typemapper
- the function that receives an element from this sequence
and returns another value for it to be emitted.java.lang.NullPointerException
- if mapper is nullpublic final Ix<T> max(java.util.Comparator<? super T> comparator)
The result's iterator() doesn't support remove().
comparator
- the comparator called with the latest maximum element and
the current element; if it returns a positive value, the current element
becomes the maximum element.java.lang.NullPointerException
- if comparator is nullmin(Comparator)
public final Ix<T> max()
The sequence may throw a ClassCastException if any of the elements is not self-comparable (i.e., doesn't implement the Comparable interface).
The result's iterator() doesn't support remove().
min()
public final Ix<java.lang.Integer> maxInt()
The sequence may throw a ClassCastException if any of the elements is not an Integer object.
The result's iterator() doesn't support remove().
public final Ix<java.lang.Long> maxLong()
The sequence may throw a ClassCastException if any of the elements is not a Long object.
The result's iterator() doesn't support remove().
public final Ix<T> mergeWith(java.lang.Iterable<? extends T> other)
Note that mergeWith and concatWith operations are the same in the Iterable world.
The result's iterator() forwards the call remove() to the current Iterator.
other
- the other sequence to emits elements ofjava.lang.NullPointerException
- if other is nullconcatWith(Iterable)
public final Ix<T> min(java.util.Comparator<? super T> comparator)
The result's iterator() doesn't support remove().
comparator
- the comparator called with the latest minimum element and
the current element; if it returns a negative value, the current element
becomes the minimum element.java.lang.NullPointerException
- if comparator is nullmax(Comparator)
public final Ix<T> min()
The sequence may throw a ClassCastException if any of the element is not self-comparable (i.e., doesn't implement the Comparable interface).
The result's iterator() doesn't support remove().
min()
public final Ix<java.lang.Integer> minInt()
The sequence may throw a ClassCastException if any of the elements is not an Integer object.
The result's iterator() doesn't support remove().
public final Ix<java.lang.Long> minLong()
The sequence may throw a ClassCastException if any of the elements is not a Long object.
The result's iterator() doesn't support remove().
public final Ix<T> orderBy()
The sequence may throw a ClassCastException if any of the elements is not a self-comparable object (i.e., doesn't implement the Comparable interface).
The result's iterator() doesn't support remove().
orderByReverse()
,
orderBy(Comparator)
public final Ix<T> orderBy(java.util.Comparator<? super T> comparator)
The result's iterator() doesn't support remove().
comparator
- the comparator comparing two elements; if it returns a negative value,
the first element will be before the second; if it returns a positive value,
the first element will be after the second.java.lang.NullPointerException
- if comparator is nullorderBy()
,
orderByReverse(Comparator)
public final <K extends java.lang.Comparable<? super K>> Ix<T> orderBy(IxFunction<? super T,K> keySelector)
The result's iterator() doesn't support remove().
K
- the key typekeySelector
- the function receiving each element and returns a self-comparable key for them.java.lang.NullPointerException
- if keySelector is nullorderByReverse(IxFunction)
public final Ix<T> orderByReverse()
The sequence may throw a ClassCastException if any of the elements is not a self-comparable object (i.e., doesn't implement the Comparable interface).
The result's iterator() doesn't support remove().
orderBy()
,
orderByReverse(Comparator)
public final Ix<T> orderByReverse(java.util.Comparator<? super T> comparator)
The result's iterator() doesn't support remove().
comparator
- the comparator comparing two elements; if it returns a negative value,
the first element will be after the second; if it returns a positive value,
the first element will be before the second.java.lang.NullPointerException
- if comparator is nullorderByReverse()
,
orderBy(Comparator)
public final <K extends java.lang.Comparable<? super K>> Ix<T> orderByReverse(IxFunction<? super T,K> keySelector)
The result's iterator() doesn't support remove().
K
- the key typekeySelector
- the function receiving each element and returns a self-comparable key for them.java.lang.NullPointerException
- if keySelector is nullorderByReverse(IxFunction)
public final Ix<T> publish()
The result's iterator() doesn't support remove().
public final <R> Ix<R> publish(IxFunction<? super Ix<T>,? extends java.lang.Iterable<? extends R>> transform)
The result's iterator() doesn't support remove().
R
- the result value typetransform
- the function that receives an Ix instance sharing a single underlying Iterator to this
sequence and returns another Iterable to be the result sequencejava.lang.NullPointerException
- if transform is nullpublic final Ix<T> reduce(IxFunction2<T,T,T> reducer)
The result's iterator() doesn't support remove().
reducer
- the function that receives the previous reduced element (or the first) and the current element
and returns a new reduced elementjava.lang.NullPointerException
- if reducer is nullreduce(IxSupplier, IxFunction2)
public final <C> Ix<C> reduce(IxSupplier<C> initialFactory, IxFunction2<C,T,C> reducer)
The result's iterator() doesn't support remove().
C
- the reduced value typeinitialFactory
- a function called for each iterator() invocation and returns the first
reduced valuereducer
- the function called with the previous (or initial) reduced value and the current element
and returns a new reduced valuejava.lang.NullPointerException
- if initialFactory or reducer is nullreduce(IxFunction2)
public final Ix<T> remove(IxPredicate<? super T> predicate)
The result's iterator() forwards the calls to remove() to this' Iterator.
predicate
- the function called with the current element and returns true
if that particular element should be removed.java.lang.NullPointerException
- if predicate is nullretain(IxPredicate)
public final Ix<T> repeat()
The result's iterator() doesn't support remove().
public final Ix<T> repeat(long times)
A count of zero will yield an empty sequence, a count of one will yield a sequence with only one element and so forth.
The result's iterator() doesn't support remove().
times
- the number of times to emit the value, non-negativejava.lang.IllegalArgumentException
- if count is negativepublic final Ix<T> repeat(IxBooleanSupplier stopPredicate)
The result's iterator() doesn't support remove().
stopPredicate
- the predicate called before any emission; returning
false keeps repeating the value, returning true terminates the sequencejava.lang.NullPointerException
- if stopPredicate is nullpublic final Ix<T> repeat(long times, IxBooleanSupplier stopPredicate)
A count of zero will yield an empty sequence, a count of one will yield a sequence with only one element and so forth.
The result's iterator() doesn't support remove().
times
- the number of times to emit the value, non-negativestopPredicate
- the predicate called before any emission; returning
false keeps repeating the value, returning true terminates the sequencejava.lang.IllegalArgumentException
- if count is negativejava.lang.NullPointerException
- if stopPredicate is nullpublic final Ix<T> replay()
The result's iterator() doesn't support remove().
public final Ix<T> replay(int size)
size
elements of this sequence to consumers of this' iterator().
Consumption by any of the iterator() may move the source sequence forward and subsequent iterator() consumers may get a different set of values
The result's iterator() doesn't support remove().
size
- the maximum number of elements to keep replaying to new iterator() consumers, positivejava.lang.IllegalArgumentException
- if size is non-positivepublic final <R> Ix<R> replay(IxFunction<? super Ix<T>,? extends java.lang.Iterable<? extends R>> transform)
The result's iterator() doesn't support remove().
R
- the result value typetransform
- the function receiving a view into the cache and returns an Iterable sequence whose
elements will be emitted by this Ix.java.lang.NullPointerException
- if transform is nullpublic final <R> Ix<R> replay(int size, IxFunction<? super Ix<T>,? extends java.lang.Iterable<? extends R>> transform)
size
elements of this sequence for the duration of the given transform function
without consuming this sequence multiple times.
Consumption by any of the inner Ix' iterator() may move the shared sequence forward and subsequent iterator() consumers may get a different set of values
The result's iterator() doesn't support remove().
R
- the result value typesize
- the maximum number of elements to keep replaying to new inner Ix iterator() consumers, positivetransform
- the function receiving a view into the cache and returns an Iterable sequence whose
elements will be emitted by this Ix.java.lang.NullPointerException
- if transform is nulljava.lang.IllegalArgumentException
- if size is non-positivepublic final Ix<T> retain(IxPredicate<? super T> predicate)
The result's iterator() forwards the calls to remove() to this' Iterator.
predicate
- the function called with the current element and returns false
if that particular element should be removed.java.lang.NullPointerException
- if predicate is nullremove(IxPredicate)
public final Ix<T> reverse()
The reversal requires consuming the entire sequence and doesn't work with infinite sequences.
The result's iterator() doesn't support remove().
public final Ix<T> scan(IxFunction2<T,T,T> scanner)
The result's iterator() doesn't support remove().
scanner
- the function that receives the previous (or first) accumulated element and the current
element and returns a value to be emitted and to become the accumulated elementjava.lang.NullPointerException
- if scanner is nullpublic final <R> Ix<R> scan(IxSupplier<R> initialFactory, IxFunction2<R,T,R> scanner)
The result's iterator() doesn't support remove().
R
- the accumulated value typeinitialFactory
- function called for each iterator() and returns the initial accumulator valuescanner
- the function that receives the previous (or first) accumulated element and the current
element and returns a value to be emitted and to become the accumulated elementjava.lang.NullPointerException
- if initialFactory or scanner is nullpublic final Ix<java.lang.Boolean> sequenceEqual(java.lang.Iterable<? extends T> other)
The result's iterator() doesn't support remove().
other
- the other sequence to compare withjava.lang.NullPointerException
- if other is nullpublic final Ix<java.lang.Boolean> sequenceEqual(java.lang.Iterable<? extends T> other, IxPredicate2<? super T,? super T> comparer)
The result's iterator() doesn't support remove().
other
- the other sequence to compare withcomparer
- the predicate receiving elements from this and the other sequence and returns true if those
elements are equaljava.lang.NullPointerException
- if other is nullpublic final Ix<T> skip(int n)
The result's iterator() forwards the calls to remove() to this' Iterator.
n
- the elements to skip, non-positive values won't skip any elementstake(int)
public final Ix<T> skipLast(int n)
The result's iterator() doesn't support remove().
n
- the elements to skip, non-positive values won't skip any elementstakeLast(int)
public final Ix<T> skipWhile(IxPredicate<? super T> predicate)
The result's iterator() forwards the calls to remove() to this' Iterator.
predicate
- the predicate called with the current element and returns true
to skip that elementjava.lang.NullPointerException
- if predicate is nulltakeWhile(IxPredicate)
public final Ix<T> startWith(T... values)
The result's iterator() doesn't support remove().
values
- the array of values to emit firstjava.lang.NullPointerException
- if values is nullpublic final Ix<java.lang.Integer> sumInt()
The operation may throw a ClassCastException if any of the elements is not an Integer.
An empty sequence yields an empty sum.
The result's iterator() doesn't support remove().
public final Ix<java.lang.Long> sumLong()
The operation may throw a ClassCastException if any of the elements is not an Long.
An empty sequence yields an empty sum.
The result's iterator() doesn't support remove().
public final Ix<T> switchIfEmpty(java.lang.Iterable<? extends T> other)
The result's Iterator forwards calls of remove() to this' or the other's Iterator.
other
- the other Iterable instance, not nulljava.lang.NullPointerException
- if other is nullpublic final Ix<T> take(int n)
The result's Iterator forwards calls of remove() to this' Iterator.
n
- the number of items to emit at most, non-negativejava.lang.IllegalArgumentException
- if n is negativeskip(int)
public final Ix<T> takeLast(int n)
The result's iterator() doesn't support remove().
n
- the number of last elements to emitjava.lang.IllegalArgumentException
- if n is negativeskipLast(int)
public final Ix<T> takeUntil(IxPredicate<? super T> stopPredicate)
The result's Iterator forwards calls of remove() to this' Iterator.
stopPredicate
- the function receiving the current element and returns
true if no further elements should be emitted after this element.java.lang.NullPointerException
- if stopPredicate is nullpublic final Ix<T> takeWhile(IxPredicate<? super T> predicate)
The result's Iterator forwards calls of remove() to this' Iterator.
predicate
- the function receiving the current element and returns
false if no further elements should be emitted (not even the current).java.lang.NullPointerException
- if predicate is nullpublic final Ix<java.lang.Long> toLong()
The sequence may throw a ClassCastException if any of the elements is not a subclass of Number.
The result's Iterator forwards calls of remove() to this' Iterator.
public final <R> Ix<R> transform(IxTransform<T,R> transformer)
The result's iterator() doesn't support remove().
R
- the result value typetransformer
- the functional interface whose moveNext is called with the
current Iterator and should signal a value to be emitted for it.java.lang.NullPointerException
- if transformer is nullpublic final Ix<T> union(java.lang.Iterable<? extends T> other)
The result's iterator() doesn't support remove().
other
- the other Iterable sequence, not nulljava.lang.NullPointerException
- if other is nullexcept(Iterable)
,
intersect(Iterable)
public final Ix<Ix<T>> window(int size)
The result's and the inner Ix' iterator() don't support remove().
size
- the maximum size of the inner windows, positivejava.lang.IllegalArgumentException
- if size is non-positivewindow(int, int)
public final Ix<Ix<T>> window(int size, int skip)
skip
source elements.size
- the maximum size of the inner windows, positiveskip
- after how many elements to start a new window (repeatedly), positivejava.lang.IllegalArgumentException
- if size or skip is non-positivewindow(int)
public final <U,R> Ix<R> zipWith(java.lang.Iterable<U> other, IxFunction2<? super T,? super U,? extends R> zipper)
If one of the source Iterables is sorter the sequence terminates eagerly.
The result's iterator() doesn't support remove().
U
- the other source's element typeR
- the result value typeother
- the the other source Iterablezipper
- the function that takes one from each source, not nulljava.lang.NullPointerException
- if other or zipper is nullpublic final T first()
java.util.NoSuchElementException
- if this sequence is emptyfirst(Object)
,
last(Object)
public final T first(T defaultValue)
public final void foreach(IxConsumer<? super T> action)
action
- the action to calljava.lang.NullPointerException
- if action is nullforeachWhile(IxPredicate)
public final void foreachWhile(IxPredicate<? super T> predicate)
predicate
- the predicate to call with the current element and should
return true to continue the loop or false to quit the loop.java.lang.NullPointerException
- if action is nullforeach(IxConsumer)
public final <U extends java.util.Collection<? super T>> U into(U collection)
U
- the collection of type accepting a (super)type of this element typecollection
- the collection to collect intojava.lang.NullPointerException
- if collection is nullpublic final T last()
java.util.NoSuchElementException
- if the sequence is emptylast(Object)
public final T last(T defaultValue)
public final void print()
public final void print(java.lang.CharSequence separator, int charsPerLine)
separator
- the characters to separate the elementscharsPerLine
- indicates how long a line should bepublic final void println()
public final void println(java.lang.CharSequence prefix)
prefix
- the prefix before each linepublic final void removeAll()
public final void removeAll(IxPredicate<? super T> predicate)
predicate
- the predicate called with the current
element and should return true for elements to remove, false
for elements to keep.java.lang.UnsupportedOperationException
- if the this Iterable
doesn't allow removing elements.retainAll(IxPredicate)
,
removeAll()
public final void retainAll(IxPredicate<? super T> predicate)
predicate
- the predicate called with the current
element and should return true for elements to keep, false
for elements to remove.java.lang.UnsupportedOperationException
- if the this Iterable
doesn't allow removing elements.removeAll(IxPredicate)
public final void run()
subscribe()
public final T single()
java.lang.IndexOutOfBoundsException
- if the sequence has more than one elementjava.util.NoSuchElementException
- if the sequence is emptysingle(Object)
public final T single(T defaultValue)
defaultValue
- the value to return if this sequence is emptyjava.lang.IndexOutOfBoundsException
- if the sequence has more than one elementsingle(Object)
public final void subscribe()
run()
public final void subscribe(IxConsumer<? super T> onNext)
onNext
- the consumer to call with each elementjava.lang.NullPointerException
- if consumer is nullpublic final void subscribe(IxConsumer<? super T> onNext, IxConsumer<java.lang.Throwable> onError)
onNext
- the consumer to call with each elementonError
- the consumer to call with the exception thrownjava.lang.NullPointerException
- if onError is nullpublic final void subscribe(IxConsumer<? super T> onNext, IxConsumer<java.lang.Throwable> onError, java.lang.Runnable onCompleted)
onNext
- the consumer to call with each elementonError
- the consumer to call with the exception thrownonCompleted
- the action called after the sequence has been consumedjava.lang.NullPointerException
- if onError or onCompleted is nullpublic final java.lang.Object[] toArray()
public final <U> U[] toArray(U[] array)
U
- the output array typearray
- the target array to fill in or use as a template if not long enoughpublic final java.util.List<T> toList()
public final <K> java.util.Map<K,T> toMap(IxFunction<? super T,? extends K> keySelector)
K
- the key typekeySelector
- the function that receives the current element and returns
a key for it to be used as the Map key.java.lang.NullPointerException
- if keySelector is nullpublic final <K,V> java.util.Map<K,V> toMap(IxFunction<? super T,? extends K> keySelector, IxFunction<? super T,? extends V> valueSelector)
K
- the key typeV
- the value typekeySelector
- the function that receives the current element and returns
a key for it to be used as the Map key.valueSelector
- the function that receives the current element and returns
a value for it to be used as the Map valuejava.lang.NullPointerException
- if keySelector or valueSelector is nullpublic final <K> java.util.Map<K,java.util.Collection<T>> toMultimap(IxFunction<? super T,? extends K> keySelector)
K
- the key typekeySelector
- the function that receives the current element and returns
a key for it to be used as the Map key.java.lang.NullPointerException
- if keySelector is nullpublic final <K,V> java.util.Map<K,java.util.Collection<V>> toMultimap(IxFunction<? super T,? extends K> keySelector, IxFunction<? super T,? extends V> valueSelector)
K
- the key typeV
- the value typekeySelector
- the function that receives the current element and returns
a key for it to be used as the Map key.valueSelector
- the function that receives the current element and returns
a value for it to be used as the Map valuejava.lang.NullPointerException
- if keySelector or valueSelector is nullpublic final java.util.Set<T> toSet()
protected static <U> U nullCheck(U value, java.lang.String message)
U
- the value typevalue
- the value to check for nullmessage
- the message to report in the exceptionprotected static <U> U checkedCall(java.util.concurrent.Callable<U> callable)
U
- the value typecallable
- the callable to callprotected static long nonNegative(long n, java.lang.String name)
n
- the number to checkname
- the name of the parameterprotected static int nonNegative(int n, java.lang.String name)
n
- the number to checkname
- the name of the parameterprotected static int positive(int n, java.lang.String name)
n
- the number to checkname
- the name of the parameter