public class Iterables extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> Iterable<T> |
concat(Iterable<T> a,
Iterable<T> b)
Iterable of lazy iterators concatenating iterators from a and b
*
|
static <T> Iterable<T> |
cycle(Iterable<T> in)
Iterable of lazy infinite iterators elements of in.
|
static <T> Iterable<T> |
drop(int num,
Iterable<T> iterable)
Iterable of lazy iterators but the num first elements of iterable
|
static <T> Iterable<T> |
dropLast(int num,
Iterable<T> iterable)
Iterable of lazy iterators emitting all elements except last num elements
|
static <T> Iterable<T> |
dropWhile(Predicate<? super T> predicate,
Iterable<T> iterable)
Iterable of lazy iterators emitting all elements but except the first matching predicate
|
static <T> Iterable<T> |
filter(Predicate<? super T> f,
Iterable<T> data)
Iterable of lazy iterators filtering another Iterable using a predicate
|
static <T> T |
first(Iterable<T> iterable)
The first element of the next iterator of iterable or null
|
static <V,A> Iterable<A> |
flatMap(Function<? super V,Iterable<A>> f,
Iterable<? extends V> data)
Iterable of lazy iterators which concatenate the result of applying map to every element in iterators of data.
|
static <A,V> A |
fold(BiFunction<? super A,? super V,? extends A> f,
A accumulator,
Iterable<? extends V> elements)
Combines elements of the first iterator into a single result by repeated application of a combining operation f where the initial result is accumulator
*
|
static <A> List<A> |
forceList(Iterable<A> iterable)
A new list with elements found in the next iterator of iterable
|
static <A> Set<A> |
forceSet(Iterable<A> iterable)
A new set with elements found in the next iterator of iterable
|
static <T> Iterable<T> |
iterable(Stream<T> stream)
Iterable of stream
|
static <T> Iterable<T> |
iterate(Function<? super T,? extends T> function,
T initial)
Iterable of lazy infinite iterators iterating over function with initial value.
|
static <T> T |
last(Iterable<T> i)
The last element of the next iterator of iterable or null
|
static <A> List<A> |
list(Iterable<A> iterable)
A list with elements found in the next iterator of iterable.
|
static <A,B,V> Iterable<V> |
map(BiFunction<? super A,? super B,V> f,
Iterable<? extends A> i1,
Iterable<? extends B> i2)
Iterable of lazy iterators applying a combining function to every element induced by two Iterables, until one of the iterators are empty.
|
static <A,V> Iterable<V> |
map(Function<? super A,V> f,
Iterable<A> data)
Iterable of lazy iterators applying a function to all element induced by a Iterable
|
static <T> Iterable<T> |
next(Iterable<T> iterable)
Iterable of lazy iterators emitting all elements but first from iterable or null if empty
|
static <T> T |
nth(int i,
Iterable<T> iterable)
The nth element of the next iterator of iterable or null
|
static <T> Iterable<Iterable<T>> |
partition(int num,
Iterable<T> iterable)
Iterable of lazy iterators partitioning elements into num long iterables
|
static <T> Iterable<Iterable<T>> |
partitionBy(Function<? super T,Object> function,
Iterable<T> iterable)
Iterable of lazy iterators partitioning elements by application to function
*
|
static Iterable<Integer> |
range()
Iterable of lazy iterators iterating from 0 to Integer.MAX_VALUE
|
static Iterable<Integer> |
range(int n)
Iterable of lazy iterators iterating from 0 to n
|
static Iterable<Integer> |
range(int from,
int to)
Iterable of lazy iterators iterating from from to to
|
static Iterable<Integer> |
range(int from,
int to,
int step)
Iterable of lazy iterators iterating from from to to in steps of step
|
static <T> T |
reduce(BiFunction<? super T,? super T,? extends T> f,
Iterable<? extends T> elements)
Combines elements of the first iterator into a single result by repeated application of a combining operation f where the initial result is first element
*
|
static <A,V> Iterable<V> |
reductions(BiFunction<? super V,? super A,? extends V> f,
V accumulator,
Iterable<? extends A> elements)
Iterable of lazy iterators producing intermediate values of the reduction of elements by f, starting with accumulator
|
static <T> Iterable<T> |
repeat(int lim,
T t) |
static <T> Iterable<T> |
repeat(T x)
Iterable of lazy infinite iterators of x
|
static <T> Iterable<T> |
repeatedly(Supplier<T> supplier)
Iterable of lazy infinite iterators with invokes of supplier
|
static <T> Iterable<T> |
rest(Iterable<T> iterable)
Iterable of lazy iterators emitting all elements but first from iterable
|
static <T> T |
second(Iterable<T> iterable)
The second element of the next iterator of iterable or null
|
static <A> Set<A> |
set(Iterable<A> iterable)
A set with elements found in the next iterator of iterable.
|
static <T> Iterable<Iterable<T>> |
splitAt(int i,
Iterable<T> iterable)
Tuple of Iterables of lazy iterators by spliting iterables iterators at i.
|
static <T> Iterable<Iterable<T>> |
splitWith(Predicate<T> p,
Iterable<T> iterable)
Tuple of Iterables of lazy iterators by spliting iterables iterators by predicate.
|
static <T> Stream<T> |
stream(Iterable<T> iterable)
Stream of iterable
|
static <T> Iterable<T> |
take(int num,
Iterable<T> iterable)
Iterable of lazy iterators having num first values of iterable
|
static <T> Iterable<T> |
takeNth(int nth,
Iterable<T> iterable)
Iterable of lazy iterators with every nth element of iterables iterator
|
static <T> Iterable<T> |
takeWhile(Predicate<? super T> pred,
Iterable<T> iterable)
Iterable of lazy iterators having the first elements matching predicate
|
static <T> Iterable<T> |
with(T t,
Iterable<? extends T> iterable)
Iterable of lazy iterators prepending t to each iterator of iterable
|
static <T> Iterable<T> |
withLast(Iterable<T> iterable,
T b)
Iterable of lazy iterators appending b to each iterator of iterable
*
|
public static <A> List<A> forceList(Iterable<A> iterable)
public static <A> List<A> list(Iterable<A> iterable)
public static <A> Set<A> forceSet(Iterable<A> iterable)
public static <A> Set<A> set(Iterable<A> iterable)
Example:
public static <A,V> A fold(BiFunction<? super A,? super V,? extends A> f, A accumulator, Iterable<? extends V> elements)
Example:
fold((a,v)->a+v, 0, Arrays.asList(1,2,3,4)) => 10
public static <T> T reduce(BiFunction<? super T,? super T,? extends T> f, Iterable<? extends T> elements)
Example:
fold((a,v)->a+v, 0, Arrays.asList(1,2,3,4)) => 10
public static <T> Iterable<T> filter(Predicate<? super T> f, Iterable<T> data)
Example:
list(filter( e -> 0==e%2, Arrays.asList(1, 2, 3, 4))) => [2, 4]
public static <A,V> Iterable<V> map(Function<? super A,V> f, Iterable<A> data)
Example:
list(map( e -> e+1, Arrays.asList(1, 2, 3, 4))) => [2, 3, 4, 5]
public static <A,B,V> Iterable<V> map(BiFunction<? super A,? super B,V> f, Iterable<? extends A> i1, Iterable<? extends B> i2)
Example:
list(map( (a,b) -> a+b, Arrays.asList(1, 2, 3, 4), Arrays.asList(1, 2, 3))) => [2, 4, 6]
public static <A,V> Iterable<V> reductions(BiFunction<? super V,? super A,? extends V> f, V accumulator, Iterable<? extends A> elements)
Example:
list( reductions( (a,b) -> a+b, 0, Arrays.asList(1, 2, 3, 4))) => [1, 3, 6, 10]
public static <T> Iterable<T> drop(int num, Iterable<T> iterable)
Example:
list( drop( 2, Arrays.asList(1, 2, 3, 4))) => [3, 4]
public static <T> T first(Iterable<T> iterable)
Example:
first( Arrays.asList(1, 2, 3, 4)) => 1
public static <T> T second(Iterable<T> iterable)
Example:
second( Arrays.asList(1, 2, 3, 4)) => 2
public static <T> T nth(int i,
Iterable<T> iterable)
Example:
nth(2, Arrays.asList(1, 2, 3, 4)) => 3
public static <T> Iterable<T> take(int num, Iterable<T> iterable)
Example:
list( take(2, Arrays.asList(1, 2, 3, 4))) => [1, 2]
public static <T> Iterable<T> takeWhile(Predicate<? super T> pred, Iterable<T> iterable)
Example:
list( takeWhile(x -> x<3, Arrays.asList(1, 2, 3, 4))) => [1, 2]
public static <T> T last(Iterable<T> i)
Example:
last( Arrays.asList(1, 2, 3, 4)) => 4
public static <T> Iterable<T> takeNth(int nth, Iterable<T> iterable)
Example:
list( takeNth(2, Arrays.asList(1, 2, 3, 4))) => [1, 3]
public static <V,A> Iterable<A> flatMap(Function<? super V,Iterable<A>> f, Iterable<? extends V> data)
Example:
list( flatMap((v) -> asList(v, v), asList(1, 2))) => [1, 1, 2, 2]
public static <T> Iterable<T> next(Iterable<T> iterable)
Example:
list( next( asList(1, 2, 3))) => [2, 2]
list( next( asList(1))) => null
public static <T> Iterable<T> rest(Iterable<T> iterable)
Example:
list( rest( asList(1, 2, 3))) => [2, 2]
list( rest( asList(1))) => []
public static <T> Iterable<T> dropLast(int num, Iterable<T> iterable)
Example:
list( dropLast( 2, asList(1, 2, 3))) => [1]
public static <T> Iterable<T> dropWhile(Predicate<? super T> predicate, Iterable<T> iterable)
Example:
list( dropWhile( e -> e<3, asList(1, 2, 3))) => [3]
public static <T> Iterable<Iterable<T>> partition(int num, Iterable<T> iterable)
Example:
list(map( Iterables::list, list( partition( 3, asList(1, 2, 3, 4, 5, 6, 7))))) => [[1, 2, 3], [4, 5, 6]]
public static <T> Iterable<Iterable<T>> partitionBy(Function<? super T,Object> function, Iterable<T> iterable)
Example:
list( map( Iterables::list, partitionBy( v -> v%2, asList(1, 3, 4, 5, 7, 6)))) => [[1, 3], [4], [5, 7], [6]]
public static <T> Iterable<Iterable<T>> splitAt(int i, Iterable<T> iterable)
Example:
list(map( Iterables::list, splitAt( 3, asList(1, 2, 3, 4, 5, 6, 7))))) => [[1, 2, 3], [4, 5, 6, 7]]
public static <T> Iterable<Iterable<T>> splitWith(Predicate<T> p, Iterable<T> iterable)
Example:
list(map( Iterables::list, splitWith(v->v%2==0, asList(4,2,3,4)))) => [[4, 2], [3, 4]]
public static <T> Iterable<T> concat(Iterable<T> a, Iterable<T> b)
Example:
list(concat( asList(1,2), asList(3,4))) => [1, 2, 3, 4]
public static <T> Iterable<T> withLast(Iterable<T> iterable, T b)
Example:
list( withLast( asList(1,2), 3 )) => [1, 2, 3]
public static <T> Iterable<T> with(T t, Iterable<? extends T> iterable)
Example:
list( with( 1, asList(2,3))) => [1, 2, 3]
public static <T> Iterable<T> iterate(Function<? super T,? extends T> function, T initial)
Example:
list(take(4, iterate(v -> v + 1, 5))) => [5, 6, 7, 8]
public static <T> Iterable<T> repeatedly(Supplier<T> supplier)
Example:
list(take(3, repeatedly(() -> 4))) => [4, 4, 4]
public static <T> Iterable<T> repeat(T x)
Example:
list(take(3, repeat( 4))) => [4, 4, 4]
public static <T> Iterable<T> repeat(int lim, T t)
public static Iterable<Integer> range()
Example:
list(take(3, range())) => [0, 1, 2]
public static Iterable<Integer> range(int n)
Example:
list(range(3)) => [0, 1, 2]
public static Iterable<Integer> range(int from, int to)
Example:
list(range(1,3)) => [1, 2]
public static Iterable<Integer> range(int from, int to, int step)
Example:
list(range(1,5,3)) => [1, 4]
Copyright © 2017. All rights reserved.