public final class Interactive
extends java.lang.Object
Iterable
based) counterparts
of the Reactive
operators.
The implementations of the operators are partially derived from the Reactive operators.
Observable
Modifier and Type | Method and Description |
---|---|
static <T,U,V> java.lang.Iterable<V> |
aggregate(java.lang.Iterable<? extends T> source,
rx.functions.Func2<? super U,? super T,? extends U> sum,
rx.functions.Func2<? super U,? super java.lang.Integer,? extends V> divide)
Creates an iterable which traverses the source iterable and maintains a running sum value based
on the
sum function parameter. |
static <T> java.lang.Iterable<java.lang.Boolean> |
all(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Returns an iterable which contains true if all
elements of the source iterable satisfy the predicate.
|
static <T> java.lang.Iterable<java.lang.Boolean> |
any(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Tests if there is any element of the source that satisfies the given predicate function.
|
static <T> java.lang.Iterable<java.lang.Boolean> |
any(java.lang.Iterable<T> source)
Determines if the given source has any elements at all.
|
static <T,V extends java.lang.Comparable<? super V>> |
argAndMax(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends V> valueSelector)
Returns a pair of the maximum argument and value from the given sequence.
|
static <T,V> Pair<T,V> |
argAndMax(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends V> valueSelector,
java.util.Comparator<? super V> valueComparator)
Returns a pair of the maximum argument and value from the given sequence.
|
static <T,V extends java.lang.Comparable<? super V>> |
argAndMin(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends V> valueSelector)
Returns a pair of the maximum argument and value from the given sequence.
|
static <T,V> Pair<T,V> |
argAndMin(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends V> valueSelector,
java.util.Comparator<? super V> valueComparator)
Returns a pair of the minimum argument and value from the given sequence.
|
static java.lang.Iterable<java.math.BigDecimal> |
averageBigDecimal(java.lang.Iterable<java.math.BigDecimal> source)
Returns an iterable which averages the source BigDecimal values.
|
static java.lang.Iterable<java.math.BigDecimal> |
averageBigInteger(java.lang.Iterable<java.math.BigInteger> source)
Returns an iterable which averages the source BigInteger values.
|
static java.lang.Iterable<java.lang.Double> |
averageDouble(java.lang.Iterable<java.lang.Double> source)
Returns an iterable which averages the source Double values.
|
static java.lang.Iterable<java.lang.Float> |
averageFloat(java.lang.Iterable<java.lang.Float> source)
Returns an iterable which averages the source Float values.
|
static java.lang.Iterable<java.lang.Double> |
averageInt(java.lang.Iterable<java.lang.Integer> source)
Returns an iterable which averages the source Integer values.
|
static java.lang.Iterable<java.lang.Double> |
averageLong(java.lang.Iterable<java.lang.Long> source)
Returns an iterable which averages the source Integer values.
|
static <T> java.lang.Iterable<java.util.List<T>> |
buffer(java.lang.Iterable<? extends T> source,
int bufferSize)
Returns an iterable which buffers the source elements
into
bufferSize lists. |
static <T> java.lang.Iterable<T> |
concat(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
Concatenate the given iterable sources one
after another in a way, that calling the second
iterator()
only happens when there is no more element in the first iterator. |
static <T> java.lang.Iterable<T> |
concat(java.lang.Iterable<? extends T> first,
java.lang.Iterable<? extends T> second)
Concatenate the given iterable sources one
after another in a way, that calling the second
iterator()
only happens when there is no more element in the first iterator. |
static <T> java.lang.Iterable<java.lang.Boolean> |
contains(java.lang.Iterable<? extends T> source,
java.lang.Object value)
Returns an iterable which checks for the existence of the supplied
value by comparing the elements of the source iterable using reference
and
equals() . |
static <T> java.lang.Iterable<java.lang.Integer> |
count(java.lang.Iterable<T> source)
Counts the elements of the iterable source by using a 32 bit
int . |
static <T> java.lang.Iterable<java.lang.Long> |
countLong(java.lang.Iterable<T> source)
Counts the elements of the iterable source by using a 64 bit
long . |
static <T> java.lang.Iterable<T> |
defer(rx.functions.Func0<? extends java.lang.Iterable<T>> func)
Defers the source iterable creation to registration time and
calls the given
func for the actual source. |
static <T> java.lang.Iterable<T> |
dematerialize(java.lang.Iterable<? extends rx.Notification<? extends T>> source)
Convert the source materialized elements into normal iterator behavior.
|
static <T> java.lang.Iterable<T> |
distinct(java.lang.Iterable<? extends T> source)
Returns an iterable which filters its elements based if they were ever seen before in
the current iteration.
|
static <T,U,V> java.lang.Iterable<V> |
distinct(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends U> keySelector,
rx.functions.Func1<? super T,? extends V> valueSelector)
Returns an iterable which filters its elements by an unique key
in a way that when multiple source items produce the same key, only
the first one ever seen gets relayed further on.
|
static <T> java.lang.Iterable<T> |
distinctNext(java.lang.Iterable<? extends T> source)
Creates an iterable which ensures that subsequent values of T are not equal (reference and equals).
|
static <T,U> java.lang.Iterable<T> |
distinctNext(java.lang.Iterable<? extends T> source,
rx.functions.Func1<T,U> keyExtractor)
Creates an iterable which ensures that subsequent values of
T are not equal in respect to the extracted keys (reference and equals).
|
static <T> java.lang.Iterable<T> |
doOnCompleted(java.lang.Iterable<? extends T> source,
rx.functions.Action0 action)
Returns an iterable which executes the given action after
the stream completes.
|
static <T> java.lang.Iterable<T> |
doOnEach(java.lang.Iterable<? extends T> source,
rx.functions.Action1<? super T> next,
rx.functions.Action0 finish)
Returns an iterable which invokes the given
next
action for each element and the finish action when
the source completes. |
static <T> java.lang.Iterable<T> |
doOnEach(java.lang.Iterable<? extends T> source,
rx.functions.Action1<? super T> next,
rx.functions.Action1<? super java.lang.Throwable> error)
Returns an iterable which invokes the given
next
action for each element and error when an exception is thrown. |
static <T> java.lang.Iterable<T> |
doOnEach(java.lang.Iterable<? extends T> source,
rx.functions.Action1<? super T> next,
rx.functions.Action1<? super java.lang.Throwable> error,
rx.functions.Action0 finish)
Returns an iterable which invokes the given
next
action for each element and the finish action when
the source completes and error when an exception is thrown. |
static <T> java.lang.Iterable<T> |
doOnNext(java.lang.Iterable<? extends T> source,
rx.functions.Action1<? super T> action)
Construct a new iterable which will invoke the specified action
before the source value gets relayed through it.
|
static <T> java.lang.Iterable<T> |
doWhile(java.lang.Iterable<? extends T> source,
rx.functions.Func0<java.lang.Boolean> gate)
Returns an iterable which reiterates over and over again on
source
as long as the gate is true. |
static boolean |
elementsEqual(java.lang.Iterable<?> iterable1,
java.lang.Iterable<?> iterable2)
Determines whether two iterables contain equal elements in the same
order.
|
static boolean |
elementsEqual(java.util.Iterator<?> iterator1,
java.util.Iterator<?> iterator2)
Compares two iterators wether they contain the same element in terms of numbers
and nullsafe Object.equals().
|
static <T> java.lang.Iterable<T> |
empty()
Returns an empty iterable which will not produce elements.
|
static <T> java.lang.Iterable<T> |
endWith(java.lang.Iterable<? extends T> source,
T value)
Creates an iterable sequence which returns all elements from source
followed by the supplied value as last.
|
static <T> java.lang.Iterable<T> |
error(java.lang.Throwable t)
Returns an iterator which will throw the given
Throwable exception when the client invokes
next() the first time. |
static <T> java.lang.Iterable<T> |
filter(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,java.lang.Boolean> predicate)
Creates an iterable which filters the source iterable with the
given predicate function.
|
static <T> java.lang.Iterable<T> |
filterIndexed(java.lang.Iterable<? extends T> source,
rx.functions.Func0<? extends rx.functions.Func2<? super java.lang.Integer,? super T,java.lang.Boolean>> predicateFactory)
Creates an iterable which filters the source iterable with the
given predicate factory function.
|
static <T> java.lang.Iterable<T> |
filterIndexed(java.lang.Iterable<? extends T> source,
rx.functions.Func2<? super java.lang.Integer,? super T,java.lang.Boolean> predicate)
Creates an iterable which filters the source iterable with the
given predicate factory function.
|
static <T> T |
first(java.lang.Iterable<? extends T> src)
Returns the first element from the iterable sequence or
throws a NoSuchElementException.
|
static <T> T |
firstOrDefault(java.lang.Iterable<? extends T> src,
T defaultValue)
Returns the first element from the sequence or the default
value if this sequence is empty
|
static <T,U> java.lang.Iterable<U> |
flatMap(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends java.lang.Iterable<? extends U>> selector)
Creates an iterable which returns a stream of Us for each source Ts.
|
static <T,U> java.lang.Iterable<U> |
flatMapAll(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends java.lang.Iterable<? extends U>> selector)
Returns an iterable which runs the source iterable and
returns elements from the iterable returned by the function call.
|
static <T> void |
forEach(java.lang.Iterable<? extends T> source,
rx.functions.Action1<? super T> action)
Iterate over the source and submit each value to the
given action.
|
static <T> java.lang.Iterable<T> |
generate(T seed,
rx.functions.Func1<? super T,java.lang.Boolean> predicate,
rx.functions.Func1<? super T,? extends T> next)
A generator function which returns Ts based on the termination condition and the way it computes the next values.
|
static <T> java.lang.Iterable<T> |
generate(T seed,
rx.functions.Func1<? super T,java.lang.Boolean> predicate,
rx.functions.Func1<? super T,? extends T> next,
long initialDelay,
long betweenDelay,
java.util.concurrent.TimeUnit unit)
A generator function which returns Ts based on the termination condition and the way it computes the next values,
but the first T to be returned is preceded by an
initialDelay amount of wait and each
subsequent element is then generated after betweenDelay sleep. |
static <T,V> java.lang.Iterable<GroupedIterable<V,T>> |
groupBy(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends V> keySelector)
Creates an iterable which traverses the source iterable,
and based on the key selector, groups values of T into GroupedIterables,
which can be iterated over later on.
|
static <T,U,V> java.lang.Iterable<GroupedIterable<V,U>> |
groupBy(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends V> keySelector,
rx.functions.Func1<? super T,? extends U> valueSelector)
Creates an iterable which traverses the source iterable,
and based on the key selector, groups values extracted by valueSelector into GroupedIterables,
which can be iterated over later on.
|
static java.lang.Iterable<java.lang.Boolean> |
isEmpty(java.lang.Iterable<?> source)
Returns a single true if the target iterable is empty.
|
static java.lang.Iterable<java.lang.String> |
join(java.lang.Iterable<?> source,
java.lang.String separator)
Concatenates the source strings one after another and uses the given separator.
|
static <T> java.lang.Iterable<T> |
just(T value)
Creates an iterable which returns only a single element.
|
static <T> T |
last(java.lang.Iterable<? extends T> source)
Returns the last element of the iterable or throws a
NoSuchElementException if the iterable is empty. |
static <T> T |
lastOrDefault(java.lang.Iterable<? extends T> source,
T defaultValue)
Returns the last element of this sequence or the default value if
this sequence is empty.
|
static <T,U> java.lang.Iterable<U> |
map(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends U> selector)
Creates an iterable which is a transforms the source
elements by using the selector function.
|
static <T,U> java.lang.Iterable<U> |
mapIndexed(java.lang.Iterable<? extends T> source,
rx.functions.Func2<? super java.lang.Integer,? super T,? extends U> selector)
Creates an iterable which is a transforms the source
elements by using the selector function.
|
static <T> java.lang.Iterable<rx.Notification<T>> |
materialize(java.lang.Iterable<? extends T> source)
Transforms the sequence of the source iterable into an option sequence of
Notification.some(), Notification.none() and Notification.error() values, depending on
what the source's hasNext() and next() produces.
|
static <T extends java.lang.Comparable<? super T>> |
max(java.lang.Iterable<? extends T> source)
Returns the maximum value of the given iterable source.
|
static <T> java.lang.Iterable<T> |
max(java.lang.Iterable<? extends T> source,
java.util.Comparator<? super T> comparator)
Returns the maximum value of the given iterable source in respect to the supplied comparator.
|
static <T extends java.lang.Comparable<? super T>> |
maxBy(java.lang.Iterable<? extends T> source)
Returns an iterator which will produce a single List of the maximum values encountered
in the source stream based on the supplied key selector.
|
static <T> java.lang.Iterable<java.util.List<T>> |
maxBy(java.lang.Iterable<? extends T> source,
java.util.Comparator<? super T> comparator)
Returns an iterator which will produce a single List of the maximum values encountered
in the source stream based on the supplied comparator.
|
static <T,U extends java.lang.Comparable<? super U>> |
maxBy(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends U> keySelector)
Returns an iterator which will produce a single List of the maximum values encountered
in the source stream based on the supplied key selector.
|
static <T,U> java.lang.Iterable<java.util.List<T>> |
maxBy(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends U> keySelector,
java.util.Comparator<? super U> keyComparator)
Returns an iterator which will produce a single List of the minimum values encountered
in the source stream based on the supplied key selector and comparator.
|
static <T> java.lang.Iterable<T> |
memoize(java.lang.Iterable<? extends T> source,
int bufferSize)
Enumerates the source iterable once and caches its results.
|
static <T> java.lang.Iterable<T> |
memoizeAll(java.lang.Iterable<? extends T> source)
The returned iterable ensures that the source iterable is only traversed once, regardless of
how many iterator attaches to it and each iterator see only the values.
|
static <T> java.lang.Iterable<T> |
merge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
Merges a bunch of iterable streams where each of the iterable will run by
a scheduler and their events are merged together in a single stream.
|
static <T> java.lang.Iterable<T> |
merge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources,
rx.Scheduler scheduler)
Merges a bunch of iterable streams where each of the iterable will run by
a scheduler and their events are merged together in a single stream.
|
static <T> java.lang.Iterable<T> |
merge(java.lang.Iterable<? extends T> first,
java.lang.Iterable<? extends T> second)
Merges two iterable streams.
|
static <T extends java.lang.Comparable<? super T>> |
min(java.lang.Iterable<? extends T> source)
Returns the minimum value of the given iterable source.
|
static <T> java.lang.Iterable<T> |
min(java.lang.Iterable<? extends T> source,
java.util.Comparator<? super T> comparator)
Returns the minimum value of the given iterable source in respect to the supplied comparator.
|
static <T extends java.lang.Comparable<? super T>> |
minBy(java.lang.Iterable<? extends T> source)
Returns an iterator which will produce a single List of the minimum values encountered
in the source stream based on the supplied key selector.
|
static <T> java.lang.Iterable<java.util.List<T>> |
minBy(java.lang.Iterable<? extends T> source,
java.util.Comparator<? super T> comparator)
Returns an iterator which will produce a single List of the minimum values encountered
in the source stream based on the supplied comparator.
|
static <T,U extends java.lang.Comparable<? super U>> |
minBy(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends U> keySelector)
Returns an iterator which will produce a single List of the minimum values encountered
in the source stream based on the supplied key selector.
|
static <T,U> java.lang.Iterable<java.util.List<T>> |
minBy(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends U> keySelector,
java.util.Comparator<? super U> keyComparator)
Returns an iterator which will produce a single List of the minimum values encountered
in the source stream based on the supplied key selector and comparator.
|
static <T> CloseableIterable<T> |
newCloseableIterable(java.lang.Iterable<? extends T> src,
rx.functions.Action0 close)
Wraps the given source sequence into a CloseableIterable instance
where the inner CloseableIterator.close() method calls the supplied action.
|
static <T> CloseableIterable<T> |
newCloseableIterable(java.lang.Iterable<? extends T> src,
rx.functions.Action1<? super java.util.Iterator<? extends T>> close)
Wraps the given source sequence into a CloseableIterable instance
where the inner CloseableIterator.close() method calls the supplied action.
|
static <T> CloseableIterable<T> |
newCloseableIterable(java.lang.Iterable<? extends T> src,
java.io.Closeable close)
Wraps the given source sequence into a CloseableIterable instance
where the inner CloseableIterator.close() method calls the supplied closeable object.
|
static <T> CloseableIterator<T> |
newCloseableIterator(java.util.Iterator<? extends T> src,
rx.functions.Action0 close)
Wraps the supplied iterator into a CloseableIterator which calls the supplied
close action.
|
static <T> CloseableIterator<T> |
newCloseableIterator(java.util.Iterator<? extends T> src,
rx.functions.Action1<? super java.util.Iterator<? extends T>> close)
Wraps the supplied iterator into a CloseableIterator which calls the supplied
close action with the given source iterator object.
|
static <T> CloseableIterator<T> |
newCloseableIterator(java.util.Iterator<? extends T> src,
java.io.Closeable close)
Wraps the supplied iterator into a CloseableIterator which calls the supplied
closeable instance.
|
static <T,U extends java.util.Iterator<T>> |
newIterable(rx.functions.Func0<U> body)
Creates a new iterable sequence by wrapping the given function to
provide the iterator.
|
static <T> java.util.Iterator<T> |
newIterator(rx.functions.Func0<java.lang.Boolean> hasNext,
rx.functions.Func0<? extends T> next)
A functional way of creating a new iterator from the supplied
hasNext and next callbacks.
|
static <T> java.util.Iterator<T> |
newIterator(rx.functions.Func0<java.lang.Boolean> hasNext,
rx.functions.Func0<? extends T> next,
rx.functions.Action0 remove)
Constructs an iterator instance by wrapping the supplied functions
into the same-named iterator methods.
|
static <T> java.lang.Iterable<T> |
ofType(java.lang.Iterable<?> source,
java.lang.Class<T> token)
Casts the source iterable into a different type by using a type token.
|
static <T> java.lang.Iterable<T> |
onErrorResumeNext(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
Creates an iterable which resumes with the next iterable from the sources when one throws an exception or completes normally.
|
static <T> java.lang.Iterable<T> |
onErrorResumeNext(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super java.lang.Throwable,? extends java.lang.Iterable<? extends T>> handler)
Creates an iterable which if iterates over the source and encounters an exception,
the iteration is continued on the new iterable returned by the handler function.
|
static <T> java.lang.Iterable<T> |
onErrorResumeNext(java.lang.Iterable<? extends T> first,
java.lang.Iterable<? extends T> second)
Creates an iterable which resumes with the next iterable from the sources when one throws an exception.
|
static <T> java.lang.Iterable<T> |
onErrorTerminate(java.lang.Iterable<? extends T> source)
Creates an iterable which if iterates over the source and encounters an exception, it simply stops the iteration, consuming the exception.
|
static <T extends java.lang.Comparable<? super T>> |
orderBy(java.lang.Iterable<? extends T> source)
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
static <T> java.lang.Iterable<T> |
orderBy(java.lang.Iterable<? extends T> source,
java.util.Comparator<? super T> comparator)
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
static <T,U extends java.lang.Comparable<? super U>> |
orderBy(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends U> keySelector)
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
static <T,U> java.lang.Iterable<T> |
orderBy(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super T,? extends U> keySelector,
java.util.Comparator<? super U> keyComparator)
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
static <T> rx.functions.Action1<T> |
print()
Creates an observer with debugging purposes.
|
static <T> rx.functions.Action1<T> |
print(java.lang.String separator,
int maxLineLength)
Creates an observer with debugging purposes.
|
static <T> rx.functions.Action1<T> |
println()
Creates an action for debugging purposes.
|
static <T> rx.functions.Action1<T> |
println(java.lang.String prefix)
Creates an action for debugging purposes.
|
static <T,U> java.lang.Iterable<U> |
prune(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super java.lang.Iterable<? extends T>,? extends java.lang.Iterable<U>> func)
Applies the
func function for a shared instance of the source,
e.g., func.call(share(source)) . |
static <T,U> java.lang.Iterable<U> |
publish(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super java.lang.Iterable<? super T>,? extends java.lang.Iterable<? extends U>> func,
U initial)
The returned iterable ensures that the source iterable is only traversed once, regardless of
how many iterator attaches to it and each iterator see only the same cached values.
|
static <T,U> java.lang.Iterable<U> |
publish(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func)
The returned iterable ensures that the source iterable is only traversed once, regardless of
how many iterator attaches to it and each iterator see only the values.
|
static java.lang.Iterable<java.lang.Integer> |
range(int start,
int count)
Creates an integer iterator which returns numbers from the start position in the count size.
|
static java.lang.Iterable<java.lang.Long> |
range(long start,
long count)
Creates an long iterator which returns numbers from the start position in the count size.
|
static <T> java.lang.Iterable<T> |
relayWhile(java.lang.Iterable<? extends T> source,
rx.functions.Func0<java.lang.Boolean> gate)
Relays the source iterable's values until the gate returns false.
|
static <T> java.lang.Iterable<T> |
repeat(T value)
Creates an iterable sequence which returns the given value indefinitely.
|
static <T> java.lang.Iterable<T> |
repeat(T value,
int count)
Returns an iterable which repeats the given single value the specified number of times.
|
static <T,U> java.lang.Iterable<U> |
replay(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func)
The returned iterable ensures that the source iterable is only traversed once, regardless of
how many iterator attaches to it and each iterator may only see one source element.
|
static <T,U> java.lang.Iterable<U> |
replay(java.lang.Iterable<? extends T> source,
rx.functions.Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func,
int bufferSize)
The returned iterable ensures that the source iterable is only traversed once, regardless of
how many iterator attaches to it and each iterator see only the some cached values.
|
static <T> java.lang.Iterable<T> |
retry(java.lang.Iterable<? extends T> source,
int count)
Creates an iterator which attempts to re-iterate the source if it threw an exception.
|
static void |
run(java.lang.Iterable<?> source)
Iterates over the given source without using its returned value.
|
static <T,U> java.lang.Iterable<U> |
scan(java.lang.Iterable<? extends T> source,
rx.functions.Func2<? super U,? super T,? extends U> aggregator)
Generates an iterable which acts like a running sum when iterating over the source iterable, e.g.,
For each element in T, it computes a value by using the current aggregation value and returns it.
|
static <T,U> java.lang.Iterable<U> |
scan(java.lang.Iterable<? extends T> source,
U seed,
rx.functions.Func2<? super U,? super T,? extends U> aggregator)
Generates an iterable which acts like a running sum when iterating over the source iterable, e.g.,
For each element in T, it computes a value by using the current aggregation value and returns it.
|
static <T> java.lang.Iterable<T> |
share(java.lang.Iterable<T> source)
Returns an iterable which ensures the source iterable is
only traversed once and clients may take values from each other,
e.g., they share the same iterator.
|
static <T,U> java.lang.Iterable<U> |
share(java.lang.Iterable<T> source,
rx.functions.Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> selector)
Shares the source sequence within the specified
selector function where each iterator can fetch
the next element from the source.
|
static int |
size(java.lang.Iterable<?> iterable)
Immediately returns the number of elements in
iterable . |
static <T> java.lang.Iterable<T> |
skip(java.lang.Iterable<? extends T> source,
int num)
Skips the specified amount of items at the beginning of the source sequence.
|
static <T> java.lang.Iterable<T> |
skipLast(java.lang.Iterable<? extends T> source,
int num)
Returns an iterable which skips the last
num elements from the
source iterable. |
static <T> java.lang.Iterable<T> |
startWith(java.lang.Iterable<? extends T> source,
T... value)
Returns an iterable which prefixes the source iterable values
by a constant.
|
static <T> java.lang.Iterable<Pair<T,T>> |
subsequent(java.lang.Iterable<? extends T> source)
Creates an iterable which returns two subsequent items from the source
iterable as pairs of values.
|
static <T> java.lang.Iterable<java.lang.Iterable<T>> |
subsequent(java.lang.Iterable<? extends T> source,
int count)
Creates an iterable which returns
count subsequent items from the source
iterable as sequence of values. |
static java.lang.Iterable<java.math.BigDecimal> |
sumBigDecimal(java.lang.Iterable<java.math.BigDecimal> source)
Sum the source of Integer values and return it as a single element.
|
static java.lang.Iterable<java.math.BigInteger> |
sumBigInteger(java.lang.Iterable<java.math.BigInteger> source)
Sum the source of Integer values and return it as a single element.
|
static java.lang.Iterable<java.lang.Double> |
sumDouble(java.lang.Iterable<java.lang.Double> source)
Sum the source of Double values and returns it as a single element.
|
static java.lang.Iterable<java.lang.Float> |
sumFloat(java.lang.Iterable<java.lang.Float> source)
Sum the source of Float values and returns it as a single element.
|
static java.lang.Iterable<java.lang.Integer> |
sumInt(java.lang.Iterable<java.lang.Integer> source)
Sum the source of Integer values and returns it as a single element.
|
static java.lang.Iterable<java.lang.Double> |
sumIntAsDouble(java.lang.Iterable<java.lang.Integer> source)
Computes and signals the sum of the values of the Integer source by using
a double intermediate representation.
|
static java.lang.Iterable<java.lang.Long> |
sumLong(java.lang.Iterable<java.lang.Long> source)
Sum the source of Long values and returns it as a single element.
|
static java.lang.Iterable<java.lang.Double> |
sumLongAsDouble(java.lang.Iterable<java.lang.Long> source)
Computes and signals the sum of the values of the Long sourceby using
a double intermediate representation.
|
static <T,U> java.lang.Iterable<U> |
switchCase(rx.functions.Func0<T> selector,
java.util.Map<T,java.lang.Iterable<U>> options)
Returns an iterable, which will query the selector for a key, then
queries the map for an Iterable.
|
static <T> java.lang.Iterable<T> |
take(java.lang.Iterable<? extends T> source,
int num)
Returns the iterable which returns the first
num element. |
static <T> java.lang.Iterable<T> |
takeLast(java.lang.Iterable<? extends T> source,
int num)
Returns an iterable which takes only the last
num elements from the
source iterable. |
static <T> Enumerable<T> |
toEnumerable(java.lang.Iterable<? extends T> e)
Convert the source Iterable into the Enumerable semantics.
|
static <T> Enumerator<T> |
toEnumerator(java.util.Iterator<? extends T> it)
Convert the given iterator to the Enumerator semantics.
|
static <T> java.lang.Iterable<T> |
toIterable(Enumerable<? extends T> e)
Convert the source enumerable into the Iterable semantics.
|
static <T> java.lang.Iterable<T> |
toIterable(T... ts)
Takes the input elements and returns an iterable which
traverses the array.
|
static <T> java.lang.Iterable<T> |
toIterablePart(int from,
int to,
T... ts)
Takes the input elements and returns an iterable which
traverses the array between the two indexes.
|
static <T> java.util.Iterator<T> |
toIterator(Enumerator<? extends T> en)
Convert the given enumerator to the Iterator semantics.
|
static void |
unsubscribe(java.util.Iterator<?> iter)
Call unsubscribe on the iterator if it implements the Subscription interface.
|
static <T,U extends java.io.Closeable> |
using(rx.functions.Func0<U> resource,
rx.functions.Func1<? super U,java.lang.Iterable<? extends T>> usage)
Returns an iterable which is associated with a closeable handler.
|
static <T,U,V> java.lang.Iterable<V> |
zip(java.lang.Iterable<? extends T> left,
java.lang.Iterable<? extends U> right,
rx.functions.Func2<? super T,? super U,? extends V> combiner)
Pairs each element from both iterable sources and
combines them into a new value by using the
combiner
function. |
public static <T,U,V> java.lang.Iterable<V> aggregate(java.lang.Iterable<? extends T> source, rx.functions.Func2<? super U,? super T,? extends U> sum, rx.functions.Func2<? super U,? super java.lang.Integer,? extends V> divide)
sum
function parameter. Once the source is depleted, it
applies the divide
function and returns its result.
This operator is a general base for averaging (where sum(u, t) => u + t
, divide(u, index) => u / index
),
summing (where sum(u, t) => u + t
, and divide(u, index) => u)
),
minimum, maximum, etc.
If the traversal of the source fails due an exception, that exception is reflected on the
next()
call of the returned iterator.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.T
- the source element typeU
- the intermediate aggregation typeV
- the resulting aggregation typesource
- the source of Tssum
- the function which takes the current intermediate value,
the current source value and should produce a new intermediate value.
for the first element of T, the U parameter will receive nulldivide
- the function which takes the last intermediate value and a total count of Ts seen and should return the final aggregation value.public static <T> java.lang.Iterable<java.lang.Boolean> all(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,java.lang.Boolean> predicate)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typesource
- the source of Tspredicate
- the predicatepublic static <T> java.lang.Iterable<java.lang.Boolean> any(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,java.lang.Boolean> predicate)
T
- the source element typesource
- the source of Tspredicate
- the predicate tester functionpublic static <T> java.lang.Iterable<java.lang.Boolean> any(java.lang.Iterable<T> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element type, irrelevant heresource
- the source of Tspublic static <T,V extends java.lang.Comparable<? super V>> Pair<T,V> argAndMax(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends V> valueSelector)
T
- the element type of the sequenceV
- the value type for the comparison, must be self comparablesource
- the source sequencevalueSelector
- the value selector functionpublic static <T,V> Pair<T,V> argAndMax(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends V> valueSelector, java.util.Comparator<? super V> valueComparator)
T
- the element typeV
- the value typesource
- the source sequence of TsvalueSelector
- the selector to extract the value from TvalueComparator
- the comparator to compare two valuespublic static <T,V extends java.lang.Comparable<? super V>> Pair<T,V> argAndMin(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends V> valueSelector)
T
- the element type of the sequenceV
- the value type for the comparison, must be self comparablesource
- the source sequencevalueSelector
- the value selector functionpublic static <T,V> Pair<T,V> argAndMin(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends V> valueSelector, java.util.Comparator<? super V> valueComparator)
T
- the element typeV
- the value typesource
- the source sequence of TsvalueSelector
- the selector to extract the value from TvalueComparator
- the comparator to compare two valuespublic static java.lang.Iterable<java.math.BigDecimal> averageBigDecimal(java.lang.Iterable<java.math.BigDecimal> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
source
- the source of BigDecimal valuespublic static java.lang.Iterable<java.math.BigDecimal> averageBigInteger(java.lang.Iterable<java.math.BigInteger> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
source
- the source of BigInteger valuespublic static java.lang.Iterable<java.lang.Double> averageDouble(java.lang.Iterable<java.lang.Double> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
source
- the source of Double valuespublic static java.lang.Iterable<java.lang.Float> averageFloat(java.lang.Iterable<java.lang.Float> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
source
- the source of Float valuespublic static java.lang.Iterable<java.lang.Double> averageInt(java.lang.Iterable<java.lang.Integer> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
source
- the source of Integer valuespublic static java.lang.Iterable<java.lang.Double> averageLong(java.lang.Iterable<java.lang.Long> source)
UnsupportedOperationException
for its remove()
method.source
- the source of Integer valuespublic static <T> java.lang.Iterable<java.util.List<T>> buffer(java.lang.Iterable<? extends T> source, int bufferSize)
bufferSize
lists.
FIXME what to do on empty source or last chunk?
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typesource
- the source of TsbufferSize
- the buffer size.public static <T> java.lang.Iterable<T> concat(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
iterator()
only happens when there is no more element in the first iterator.
The returned iterator forwards all remove()
calls
to the current source (e.g., you can remove the same elements from
multiple collections with a single traversal on the concat result).
T
- the element typesources
- the list of iterables to concatenatepublic static <T> java.lang.Iterable<T> concat(java.lang.Iterable<? extends T> first, java.lang.Iterable<? extends T> second)
iterator()
only happens when there is no more element in the first iterator.
The returned iterator forwards all remove()
calls
to the current source (first or next).
T
- the element typefirst
- the first iterablesecond
- the second iterablepublic static <T> java.lang.Iterable<java.lang.Boolean> contains(java.lang.Iterable<? extends T> source, java.lang.Object value)
equals()
. The iterable then returns a single true or false.T
- the source element typesource
- the sourcevalue
- the value to checkpublic static <T> java.lang.Iterable<java.lang.Integer> count(java.lang.Iterable<T> source)
int
.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typesource
- the source iterablepublic static <T> java.lang.Iterable<java.lang.Long> countLong(java.lang.Iterable<T> source)
long
.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typesource
- the source iterablepublic static <T> java.lang.Iterable<T> defer(rx.functions.Func0<? extends java.lang.Iterable<T>> func)
func
for the actual source.T
- the element typefunc
- the function that returns an iterable.public static <T> java.lang.Iterable<T> dematerialize(java.lang.Iterable<? extends rx.Notification<? extends T>> source)
UnsupportedOperationException
for its remove()
method.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typessource
- the source of T optionspublic static <T> java.lang.Iterable<T> distinct(java.lang.Iterable<? extends T> source)
equals()
T
- the source element typesource
- the source of Tspublic static <T,U,V> java.lang.Iterable<V> distinct(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends U> keySelector, rx.functions.Func1<? super T,? extends V> valueSelector)
equals()
T
- the source element typeU
- the key element typeV
- the output element typesource
- the source of TskeySelector
- the key selector for only-once filteringvalueSelector
- the value select for the output of the first key casespublic static <T> java.lang.Iterable<T> distinctNext(java.lang.Iterable<? extends T> source)
T
- the element typesource
- the source iterablepublic static <T,U> java.lang.Iterable<T> distinctNext(java.lang.Iterable<? extends T> source, rx.functions.Func1<T,U> keyExtractor)
T
- the element typeU
- the key typesource
- the source iterablekeyExtractor
- the function to extract the keys which will be comparedpublic static <T> java.lang.Iterable<T> doOnNext(java.lang.Iterable<? extends T> source, rx.functions.Action1<? super T> action)
The returned iterator forwards all remove()
calls
to the source.
T
- the returned element typesource
- the source iterableaction
- the action to invoke before each next() is returned.public static <T> java.lang.Iterable<T> doWhile(java.lang.Iterable<? extends T> source, rx.functions.Func0<java.lang.Boolean> gate)
source
as long as the gate is true. The gate function is checked only
when a pass over the source stream was completed.
Note that using this operator on an empty iterable may result
in a direct infinite loop in hasNext() or next() calls depending on the gate function.
The returned iterator forwards all remove()
calls
to the source.
T
- the source element typesource
- the source of Tsgate
- the gate function to stop the repeatpublic static boolean elementsEqual(java.lang.Iterable<?> iterable1, java.lang.Iterable<?> iterable2)
true
if
iterable1
and iterable2
contain the same number of
elements and every element of iterable1
is equal to the
corresponding element of iterable2
.iterable1
- the first iterableiterable2
- the second iterablepublic static boolean elementsEqual(java.util.Iterator<?> iterator1, java.util.Iterator<?> iterator2)
iterator1
- the first iteratoriterator2
- the second interatorpublic static <T> java.lang.Iterable<T> empty()
hasNext()
returns always false,
next()
throws a NoSuchElementException
and remove()
throws an IllegalStateException
.
Note that the Collections.emptyIterable()
static method is introduced by Java 7.T
- the element type, irrelevantpublic static <T> java.lang.Iterable<T> endWith(java.lang.Iterable<? extends T> source, T value)
The returned iterable forwards all remove()
methods to the source iterable, except the last element where it
throws UnsupportedOperationException.
T
- the element typesource
- the source sequencevalue
- the value to appendpublic static <T> java.lang.Iterable<T> doOnCompleted(java.lang.Iterable<? extends T> source, rx.functions.Action0 action)
The returned iterator forwards all remove()
calls
to the source.
T
- the element typesource
- the source of Tsaction
- the action to invokepublic static <T> T first(java.lang.Iterable<? extends T> src)
T
- the value typesrc
- the source sequencepublic static <T> T firstOrDefault(java.lang.Iterable<? extends T> src, T defaultValue)
T
- the value typesrc
- the source sequencedefaultValue
- the default value to returnpublic static <T,U> java.lang.Iterable<U> flatMapAll(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends java.lang.Iterable<? extends U>> selector)
Iterable<U>
s are
created before their concatenation starts.T
- the source element typeU
- the output element typesource
- the sourceselector
- the result selectorpublic static <T> void forEach(java.lang.Iterable<? extends T> source, rx.functions.Action1<? super T> action)
T
- the element type of the iterablesource
- the iterableaction
- the action to invoke on with elementpublic static <T> java.lang.Iterable<T> generate(T seed, rx.functions.Func1<? super T,java.lang.Boolean> predicate, rx.functions.Func1<? super T,? extends T> next)
T value = seed;
while (predicate(value)) {
yield value;
value = next(value);
}
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typeseed
- the initial valuepredicate
- the predicate to terminate the processnext
- the function that computes the next value.public static <T> java.lang.Iterable<T> generate(T seed, rx.functions.Func1<? super T,java.lang.Boolean> predicate, rx.functions.Func1<? super T,? extends T> next, long initialDelay, long betweenDelay, java.util.concurrent.TimeUnit unit)
initialDelay
amount of wait and each
subsequent element is then generated after betweenDelay
sleep.
The sleeping is blocking the current thread which invokes the hasNext()/next() methods.
This is equivalent to:
T value = seed;
sleep(initialDelay);
if (predicate(value)) {
yield value;
}
value = next(value);
sleep(betweenDelay);
while (predicate(value)) {
yield value;
value = next(value);
sleep(betweenDelay);
}
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typeseed
- the initial valuepredicate
- the predicate to terminate the processnext
- the function that computes the next value.initialDelay
- the initial delaybetweenDelay
- the between delayunit
- the time unit for initialDelay and betweenDelaypublic static <T,V> java.lang.Iterable<GroupedIterable<V,T>> groupBy(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends V> keySelector)
equals()
equality.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typeV
- the result group keyssource
- the source of TskeySelector
- the key selectorpublic static <T,U,V> java.lang.Iterable<GroupedIterable<V,U>> groupBy(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends V> keySelector, rx.functions.Func1<? super T,? extends U> valueSelector)
equals()
equality.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typeU
- the result group element typeV
- the result group keyssource
- the source of TskeySelector
- the key selectorvalueSelector
- the value selectorpublic static <T> java.lang.Iterable<T> doOnEach(java.lang.Iterable<? extends T> source, rx.functions.Action1<? super T> next, rx.functions.Action0 finish)
next
action for each element and the finish
action when
the source completes.T
- the source element typesource
- the source of Tsnext
- the action to invoke on each elementfinish
- the action to invoke after the last elementpublic static <T> java.lang.Iterable<T> doOnEach(java.lang.Iterable<? extends T> source, rx.functions.Action1<? super T> next, rx.functions.Action1<? super java.lang.Throwable> error)
next
action for each element and error
when an exception is thrown.T
- the source element typesource
- the source of Tsnext
- the action to invoke on each elementerror
- the error action to invoke for an errorpublic static <T> java.lang.Iterable<T> doOnEach(java.lang.Iterable<? extends T> source, rx.functions.Action1<? super T> next, rx.functions.Action1<? super java.lang.Throwable> error, rx.functions.Action0 finish)
next
action for each element and the finish
action when
the source completes and error
when an exception is thrown.
The returned iterator forwards all remove()
calls
to the source.
T
- the source element typesource
- the source of Tsnext
- the action to invoke on each elementerror
- the error action to invoke for an errorfinish
- the action to invoke after the last elementpublic static java.lang.Iterable<java.lang.Boolean> isEmpty(java.lang.Iterable<?> source)
source
- source iterable with any typepublic static java.lang.Iterable<java.lang.String> join(java.lang.Iterable<?> source, java.lang.String separator)
The returned iterator forwards all remove()
calls
to the source.
source
- the sourceseparator
- the separator to usepublic static <T> T last(java.lang.Iterable<? extends T> source)
NoSuchElementException
if the iterable is empty.T
- the source element typesource
- the source of Tspublic static <T> T lastOrDefault(java.lang.Iterable<? extends T> source, T defaultValue)
T
- the source element typesource
- the source of TsdefaultValue
- the default value to return if this sequence is emptypublic static <T,U> java.lang.Iterable<U> map(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends U> selector)
T
- the source element typeU
- the output element typesource
- the source iterableselector
- the selector functionpublic static <T,U> java.lang.Iterable<U> mapIndexed(java.lang.Iterable<? extends T> source, rx.functions.Func2<? super java.lang.Integer,? super T,? extends U> selector)
The returned iterator forwards all remove()
calls
to the source.
T
- the source element typeU
- the output element typesource
- the source iterableselector
- the selector functionpublic static <T> java.lang.Iterable<rx.Notification<T>> materialize(java.lang.Iterable<? extends T> source)
UnsupportedOperationException
for its remove()
method.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typesource
- the source of at least Ts.public static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<T> max(java.lang.Iterable<? extends T> source)
T
- the element type, which must be self comparablesource
- the source elementspublic static <T> java.lang.Iterable<T> max(java.lang.Iterable<? extends T> source, java.util.Comparator<? super T> comparator)
T
- the element type, which must be self comparablesource
- the source elementscomparator
- the comparator to usepublic static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<java.util.List<T>> maxBy(java.lang.Iterable<? extends T> source)
T
- the source element type, which must be self comparablesource
- the source of Tspublic static <T> java.lang.Iterable<java.util.List<T>> maxBy(java.lang.Iterable<? extends T> source, java.util.Comparator<? super T> comparator)
T
- the source element typesource
- the source of Tscomparator
- the key comparatorpublic static <T,U extends java.lang.Comparable<? super U>> java.lang.Iterable<java.util.List<T>> maxBy(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends U> keySelector)
T
- the source element typeU
- the key type, which must be self-comparablesource
- the source of TskeySelector
- the selector for keyspublic static <T,U> java.lang.Iterable<java.util.List<T>> maxBy(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends U> keySelector, java.util.Comparator<? super U> keyComparator)
T
- the source element typeU
- the key typesource
- the source of TskeySelector
- the selector for keyskeyComparator
- the key comparatorpublic static <T> java.lang.Iterable<T> memoize(java.lang.Iterable<? extends T> source, int bufferSize)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typesource
- the source of TsbufferSize
- the size of the bufferingpublic static <T> java.lang.Iterable<T> memoizeAll(java.lang.Iterable<? extends T> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typesource
- the source of Tspublic static <T> java.lang.Iterable<T> merge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
UnsupportedOperationException
in its remove()
method.T
- the element typesources
- the iterable of source iterables.public static <T> java.lang.Iterable<T> merge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources, rx.Scheduler scheduler)
UnsupportedOperationException
in its remove()
method.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typesources
- the iterable of source iterables.scheduler
- the scheduler for running each inner iterable in parallelpublic static <T> java.lang.Iterable<T> merge(java.lang.Iterable<? extends T> first, java.lang.Iterable<? extends T> second)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typefirst
- the first iterablesecond
- the second iterablepublic static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<T> min(java.lang.Iterable<? extends T> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element type, which must be self comparablesource
- the source elementspublic static <T> java.lang.Iterable<T> min(java.lang.Iterable<? extends T> source, java.util.Comparator<? super T> comparator)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element type, which must be self comparablesource
- the source elementscomparator
- the comparator to usepublic static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<java.util.List<T>> minBy(java.lang.Iterable<? extends T> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element type, which must be self comparablesource
- the source of Tspublic static <T> java.lang.Iterable<java.util.List<T>> minBy(java.lang.Iterable<? extends T> source, java.util.Comparator<? super T> comparator)
T
- the source element typesource
- the source of Tscomparator
- the key comparatorpublic static <T,U extends java.lang.Comparable<? super U>> java.lang.Iterable<java.util.List<T>> minBy(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends U> keySelector)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typeU
- the key type, which must be self-comparablesource
- the source of TskeySelector
- the selector for keyspublic static <T,U> java.lang.Iterable<java.util.List<T>> minBy(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends U> keySelector, java.util.Comparator<? super U> keyComparator)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typeU
- the key typesource
- the source of TskeySelector
- the selector for keyskeyComparator
- the key comparatorpublic static <T> CloseableIterable<T> newCloseableIterable(java.lang.Iterable<? extends T> src, rx.functions.Action0 close)
T
- the element typesrc
- the source sequenceclose
- the close action.public static <T> CloseableIterable<T> newCloseableIterable(java.lang.Iterable<? extends T> src, rx.functions.Action1<? super java.util.Iterator<? extends T>> close)
T
- the element typesrc
- the source sequenceclose
- the close action.public static <T> CloseableIterable<T> newCloseableIterable(java.lang.Iterable<? extends T> src, java.io.Closeable close)
T
- the element typesrc
- the source sequenceclose
- the closeable object.public static <T> CloseableIterator<T> newCloseableIterator(java.util.Iterator<? extends T> src, rx.functions.Action0 close)
T
- the element typesrc
- the source iteratorclose
- the close actionpublic static <T> CloseableIterator<T> newCloseableIterator(java.util.Iterator<? extends T> src, rx.functions.Action1<? super java.util.Iterator<? extends T>> close)
T
- the element typesrc
- the source iteratorclose
- the close actionpublic static <T> CloseableIterator<T> newCloseableIterator(java.util.Iterator<? extends T> src, java.io.Closeable close)
T
- the element typesrc
- the source iteratorclose
- the closeable instancepublic static <T,U extends java.util.Iterator<T>> java.lang.Iterable<T> newIterable(rx.functions.Func0<U> body)
T
- the element typeU
- the iterator typebody
- the body function returning an iteratorpublic static <T> java.util.Iterator<T> newIterator(rx.functions.Func0<java.lang.Boolean> hasNext, rx.functions.Func0<? extends T> next)
The returned iterator throws a UnsupportedOperationException
in its remove method.
T
- the element typehasNext
- function that returns true if more elements are available.next
- function that returns the next elementpublic static <T> java.util.Iterator<T> newIterator(rx.functions.Func0<java.lang.Boolean> hasNext, rx.functions.Func0<? extends T> next, rx.functions.Action0 remove)
T
- the element typehasNext
- function that returns true if more elements are available.next
- function that returns the next elementremove
- function to remove the current elementpublic static <T> java.lang.Iterable<T> ofType(java.lang.Iterable<?> source, java.lang.Class<T> token)
next()
will throw a ClassCastException
.
The returned iterator forwards all remove()
calls
to the source.
T
- the result element typesource
- the arbitrary sourcetoken
- the type tokenpublic static <T> java.lang.Iterable<T> onErrorResumeNext(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super java.lang.Throwable,? extends java.lang.Iterable<? extends T>> handler)
The returned iterator forwards all remove()
calls
to the source.
T
- the element typesource
- the source iterable.handler
- the exception handler.public static <T> java.lang.Iterable<T> onErrorTerminate(java.lang.Iterable<? extends T> source)
T
- the element typesource
- the source iterable.public static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<T> orderBy(java.lang.Iterable<? extends T> source)
T
- the source element type, must be self comparablesource
- the source of Tspublic static <T> java.lang.Iterable<T> orderBy(java.lang.Iterable<? extends T> source, java.util.Comparator<? super T> comparator)
T
- the source element type, must be self comparablesource
- the source of Tscomparator
- the value comparatorpublic static <T,U extends java.lang.Comparable<? super U>> java.lang.Iterable<T> orderBy(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends U> keySelector)
T
- the source element typeU
- the key type for the ordering, must be self comparablesource
- the source of TskeySelector
- the key selector for comparisonpublic static <T,U> java.lang.Iterable<T> orderBy(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends U> keySelector, java.util.Comparator<? super U> keyComparator)
T
- the source element typeU
- the key type for the orderingsource
- the source of TskeySelector
- the key selector for comparisonkeyComparator
- the key comparator functionpublic static <T> rx.functions.Action1<T> print()
T
- the value typepublic static <T> rx.functions.Action1<T> print(java.lang.String separator, int maxLineLength)
T
- the value typeseparator
- the separator to use between subsequent valuesmaxLineLength
- how many characters to print into each linepublic static <T> rx.functions.Action1<T> println()
T
- the value typepublic static <T> rx.functions.Action1<T> println(java.lang.String prefix)
T
- the value typeprefix
- the prefix to use when printingpublic static <T,U> java.lang.Iterable<U> prune(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super java.lang.Iterable<? extends T>,? extends java.lang.Iterable<U>> func)
func
function for a shared instance of the source,
e.g., func.call(share(source))
.T
- the source element typeU
- the return typessource
- the source of Tsfunc
- invoke the function on the buffering iterable and return an iterator over it.public static <T,U> java.lang.Iterable<U> publish(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super java.lang.Iterable<? super T>,? extends java.lang.Iterable<? extends U>> func, U initial)
The returned iterator will throw an UnsupportedOperationException
for remove()
method of its first element, then it might throw for any
subsequent element, depending on the source iterable.
T
- the source element typeU
- the return typessource
- the source of Tsfunc
- invoke the function on the buffering iterable and return an iterator over it.initial
- the initial value to append to the output streampublic static <T,U> java.lang.Iterable<U> publish(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typeU
- the return typessource
- the source of Tsfunc
- invoke the function on the buffering iterable and return an iterator over it.public static java.lang.Iterable<java.lang.Integer> range(int start, int count)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
start
- the starting value.count
- the number of elements to return, negative count means counting down from the start.public static java.lang.Iterable<java.lang.Long> range(long start, long count)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
start
- the starting value.count
- the number of elements to return, negative count means counting down from the start.public static <T> java.lang.Iterable<T> relayWhile(java.lang.Iterable<? extends T> source, rx.functions.Func0<java.lang.Boolean> gate)
T
- the source element typesource
- the source of Tsgate
- the gate to stop the relayingpublic static <T> java.lang.Iterable<T> repeat(T value)
(E.g., having the hasNext() always return true and the next() always return the value.
The returned iterable does not support the remove()
method.
T
- the value typevalue
- the value to repeatpublic static <T> java.lang.Iterable<T> repeat(T value, int count)
The returned iterable does not support the remove()
method.
T
- the value typevalue
- the value to repeatcount
- the repeat amountpublic static <T,U> java.lang.Iterable<U> replay(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typeU
- the return typessource
- the source of Tsfunc
- invoke the function on the buffering iterable and return an iterator over it.public static <T,U> java.lang.Iterable<U> replay(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func, int bufferSize)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the source element typeU
- the return typessource
- the source of Tsfunc
- invoke the function on the buffering iterable and return an iterator over it.bufferSize
- the buffer sizepublic static <T> java.lang.Iterable<T> onErrorResumeNext(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
The returned iterator forwards all remove()
calls
to the source.
T
- the source element typesources
- the list of sources to try one after anotherpublic static <T> java.lang.Iterable<T> onErrorResumeNext(java.lang.Iterable<? extends T> first, java.lang.Iterable<? extends T> second)
T
- the source element typefirst
- the first sourcesecond
- the second sourcepublic static <T> java.lang.Iterable<T> retry(java.lang.Iterable<? extends T> source, int count)
while (count-- > 0) {
try {
for (T t : source) {
yield t;
}
break;
} catch (Throwable t) {
if (count <= 0) {
throw t;
}
}
}
The returned iterator forwards all remove()
calls
to the source.
T
- the source typesource
- the source of Tscount
- the number of retry attemptspublic static void run(java.lang.Iterable<?> source)
source
- the source iterable to run throughpublic static <T,U> java.lang.Iterable<U> scan(java.lang.Iterable<? extends T> source, rx.functions.Func2<? super U,? super T,? extends U> aggregator)
T
- the source element typeU
- the destination element typesource
- the source of Tsaggregator
- the function which takes the current running aggregation value, the current element and produces a new aggregation value.public static <T,U> java.lang.Iterable<U> scan(java.lang.Iterable<? extends T> source, U seed, rx.functions.Func2<? super U,? super T,? extends U> aggregator)
The returned iterator forwards all remove()
calls
to the source.
T
- the source element typeU
- the destination element typesource
- the source of Tsseed
- the initial value of the running aggregationaggregator
- the function which takes the current running aggregation value, the current element and produces a new aggregation value.public static <T,U> java.lang.Iterable<U> flatMap(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,? extends java.lang.Iterable<? extends U>> selector)
The returned iterator forwards all remove()
calls
to the current source (which might not accept it).
T
- the source element typeU
- the output element typesource
- the sourceselector
- the selector for multiple Us for each Tpublic static <T> java.lang.Iterable<T> share(java.lang.Iterable<T> source)
T
- the source element typesource
- the source iterablepublic static <T,U> java.lang.Iterable<U> share(java.lang.Iterable<T> source, rx.functions.Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> selector)
T
- the source element typeU
- the result element typesource
- the source sequenceselector
- the selector functionpublic static <T> java.lang.Iterable<T> just(T value)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typevalue
- the value to returnpublic static int size(java.lang.Iterable<?> iterable)
iterable
.iterable
- the input sequencepublic static <T> java.lang.Iterable<T> skip(java.lang.Iterable<? extends T> source, int num)
T
- the element typesource
- the source iterablenum
- the number of elements to skippublic static <T> java.lang.Iterable<T> skipLast(java.lang.Iterable<? extends T> source, int num)
num
elements from the
source iterable.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typesource
- the source iterablenum
- the number of elements to skip at the endpublic static <T> java.lang.Iterable<T> startWith(java.lang.Iterable<? extends T> source, T... value)
concat(singleton(value), source)
.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method for the first element, and might
throw for subsequent elements, depending on the source iterable.
T
- the element typesource
- the source iterablevalue
- the value to prefixpublic static <T> java.lang.Iterable<Pair<T,T>> subsequent(java.lang.Iterable<? extends T> source)
source
contains zero or one elements, this
iterable will be empty.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typesource
- the source iterablepublic static <T> java.lang.Iterable<java.lang.Iterable<T>> subsequent(java.lang.Iterable<? extends T> source, int count)
count
subsequent items from the source
iterable as sequence of values.
If the source
contains less than count
elements, this
iterable will be empty.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typesource
- the source iterablecount
- the element countpublic static java.lang.Iterable<java.math.BigDecimal> sumBigDecimal(java.lang.Iterable<java.math.BigDecimal> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
source
- the sourcepublic static java.lang.Iterable<java.math.BigInteger> sumBigInteger(java.lang.Iterable<java.math.BigInteger> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
source
- the sourcepublic static java.lang.Iterable<java.lang.Double> sumDouble(java.lang.Iterable<java.lang.Double> source)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
source
- the sourcepublic static java.lang.Iterable<java.lang.Float> sumFloat(java.lang.Iterable<java.lang.Float> source)
source
- the sourcepublic static java.lang.Iterable<java.lang.Integer> sumInt(java.lang.Iterable<java.lang.Integer> source)
source
- the sourcepublic static java.lang.Iterable<java.lang.Double> sumIntAsDouble(java.lang.Iterable<java.lang.Integer> source)
source
- the source of integers to aggregate.public static java.lang.Iterable<java.lang.Long> sumLong(java.lang.Iterable<java.lang.Long> source)
source
- the sourcepublic static java.lang.Iterable<java.lang.Double> sumLongAsDouble(java.lang.Iterable<java.lang.Long> source)
source
- the source of longs to aggregate.public static <T,U> java.lang.Iterable<U> switchCase(rx.functions.Func0<T> selector, java.util.Map<T,java.lang.Iterable<U>> options)
T
- the key typeU
- the output typeselector
- the key selectoroptions
- the available options inpublic static <T> java.lang.Iterable<T> take(java.lang.Iterable<? extends T> source, int num)
num
element.
from the source iterable.
The returned iterator forwards all remove()
calls
to the source.
T
- the source element typesource
- the source of Tsnum
- the number of items to takepublic static <T> java.lang.Iterable<T> takeLast(java.lang.Iterable<? extends T> source, int num)
num
elements from the
source iterable.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typesource
- the source iterablenum
- the number of elements to skip at the endpublic static <T> java.lang.Iterable<T> error(java.lang.Throwable t)
Throwable
exception when the client invokes
next()
the first time. Any subsequent
next()
call will simply throw a NoSuchElementException
.
Calling remove()
will always throw a IllegalStateException
.
If the given Throwable instance extends a RuntimeException
, it is throws
as is, but when the throwable is a checked exception, it is wrapped
into a RuntimeException
.T
- the element type, irrelevantt
- the exception to throwpublic static <T> Enumerable<T> toEnumerable(java.lang.Iterable<? extends T> e)
T
- the source element typee
- the iterablepublic static <T> Enumerator<T> toEnumerator(java.util.Iterator<? extends T> it)
T
- the element typeit
- the source iteratorpublic static <T> java.lang.Iterable<T> toIterable(Enumerable<? extends T> e)
T
- the source element typee
- the enumerablepublic static <T> java.lang.Iterable<T> toIterable(T... ts)
The resulting Iterable
does not support remove()
.
T
- the element typets
- the input arraypublic static <T> java.lang.Iterable<T> toIterablePart(int from, int to, T... ts)
The resulting Iterable
does not support remove()
.
T
- the element typefrom
- the starting index inclusiveto
- the end index exclusivets
- the input arraypublic static <T> java.util.Iterator<T> toIterator(Enumerator<? extends T> en)
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the element typeen
- the source enumeratorpublic static void unsubscribe(java.util.Iterator<?> iter)
iter
- the iterator to unsubscribepublic static <T,U extends java.io.Closeable> java.lang.Iterable<T> using(rx.functions.Func0<U> resource, rx.functions.Func1<? super U,java.lang.Iterable<? extends T>> usage)
Closeable.close()
on the handler.
The returned iterator forwards all remove()
calls
to the source.
T
- the source element typeU
- the closeable typeresource
- the function which returns a resource tokenusage
- the function which gives an iterable for a resource token.public static <T> java.lang.Iterable<T> filterIndexed(java.lang.Iterable<? extends T> source, rx.functions.Func0<? extends rx.functions.Func2<? super java.lang.Integer,? super T,java.lang.Boolean>> predicateFactory)
The returned iterator forwards all remove()
calls
to the source.
T
- the element typesource
- the source iterablepredicateFactory
- the predicate factory which should return a new predicate function for each iterator.public static <T> java.lang.Iterable<T> filter(java.lang.Iterable<? extends T> source, rx.functions.Func1<? super T,java.lang.Boolean> predicate)
T
- the element typesource
- the source iterablepredicate
- the predicate functionpublic static <T> java.lang.Iterable<T> filterIndexed(java.lang.Iterable<? extends T> source, rx.functions.Func2<? super java.lang.Integer,? super T,java.lang.Boolean> predicate)
T
- the element typesource
- the source iterablepredicate
- the predicatepublic static <T,U,V> java.lang.Iterable<V> zip(java.lang.Iterable<? extends T> left, java.lang.Iterable<? extends U> right, rx.functions.Func2<? super T,? super U,? extends V> combiner)
combiner
function.
The returned iterator will throw an UnsupportedOperationException
for its remove()
method.
T
- the left source typeU
- the right source typeV
- the result typeleft
- the left sourceright
- the right sourcecombiner
- the combiner function