public class Iterables extends Object
| Modifier and Type | Method and Description |
|---|---|
static <A> boolean |
addAll(Collection<A> collectionToModify,
Iterable<? extends A> elementsToAdd)
Add all the elements of the iterable to the collection
|
static <A> boolean |
all(Iterable<? extends A> as,
Predicate<? super A> p)
Check if all elements in the input iterable match the input predicate
|
static <A> boolean |
any(Iterable<? extends A> as,
Predicate<? super A> p)
Check if the iterable contains any elements that match the predicate.
|
static <A,B> Iterable<B> |
ap(Iterable<A> as,
Iterable<Function<A,B>> fs)
Performs function application within an iterable (applicative functor
pattern).
|
static <A,B> Iterable<B> |
collect(Iterable<? extends A> from,
Function<? super A,Option<B>> partial)
Filters and maps (aka transforms) the unfiltered iterable.
|
static <T,A,R> R |
collect(Iterable<T> elements,
Collector<T,A,R> collector)
|
static <A> Iterable<A> |
concat(Iterable<? extends A>... as)
Concatenate a series of iterables into a single iterable.
|
static <A> Iterable<A> |
cycle(A... as)
Return an infinite iterable that cycles through the input values in order
in a loop.
|
static <A> Iterable<A> |
cycle(Iterable<? extends A> as)
Return an infinite iterable that cycles through the input values in order
in a loop.
|
static <A> Iterable<A> |
drop(int n,
Iterable<A> as)
Drop the first
n as and return the rest. |
static <A> Iterable<A> |
dropWhile(Iterable<A> as,
Predicate<A> p)
Drop elements of
as until an element returns false for
p#test |
static <T> Iterable<T> |
emptyIterable()
Returns an empty iterable, that is, an
Iterable with an
Iterator for which hasNext() always returns false,
and the other methods throw appropriate exceptions if called. |
static <A> Iterable<A> |
filter(Iterable<A> as,
Predicate<? super A> p)
Remove elements from the input iterable for which the predicate returns
false
|
static <T> Option<T> |
findFirst(Iterable<? extends T> elements,
Predicate<? super T> p)
Finds the first item that matches the predicate.
|
static <A> Function<Iterable<A>,Option<A>> |
findFirst(Predicate<? super A> predicate)
Partial application of the predicate argument to
findFirst(Iterable, Predicate) returning a function that takes an
Iterable as its argument |
static <A> Option<A> |
first(Iterable<A> as)
If
as is empty, returns none(). |
static <A,B> Iterable<B> |
flatMap(Iterable<A> collection,
Function<? super A,? extends Iterable<? extends B>> f)
Applies
f to each element of collection, then concatenates
the result. |
static <A> Iterable<A> |
intersperse(Iterable<? extends A> as,
A a)
Intersperse an element between all the elements in an iterable.
|
static <A> Iterable<A> |
intersperse(Iterable<? extends A> as,
Supplier<A> a)
Intersperse an element between all the elements in an iterable.
|
static Predicate<Iterable<?>> |
isEmpty()
Predicate that checks if an iterable is empty.
|
static <A> Iterable<A> |
iterable(A... as)
Creates an Iterable from the underlying array of elements.
|
static <A> Iterable<A> |
iterate(Function<? super A,? extends A> f,
A start)
Returns an infinite Iterable constructed by applying the given iteration
function starting at the given value.
|
static <A> Iterable<A> |
join(Iterable<? extends Iterable<? extends A>> ias)
Join Iterable<Iterable<A>> down to Iterable<A>.
|
static <A> String |
makeString(Iterable<? extends A> as,
String start,
String sep,
String end)
Pretty print an Iterable.
|
static <A> String |
makeString(Iterable<? extends A> as,
String start,
String sep,
String end,
int maxLength)
Pretty print an Iterable.
|
static <A,B> Iterable<B> |
map(Iterable<A> as,
Function<? super A,? extends B> f)
Apply the input function to each of the elements of the input iterable
returning a new iterable
|
static <A> Iterable<A> |
memoize(Iterable<A> xs)
Makes a lazy copy of
xs. |
static <A extends Comparable<A>> |
mergeSorted(Iterable<? extends Iterable<A>> xss)
Merge a number of already sorted collections of elements into a single
collection of elements, using the elements natural ordering.
|
static <A> Iterable<A> |
mergeSorted(Iterable<? extends Iterable<A>> xss,
Comparator<A> ordering)
Merge a number of already sorted collections of elements into a single
collection of elements.
|
static <A> Pair<Iterable<A>,Iterable<A>> |
partition(Iterable<A> iterable,
Predicate<? super A> p)
Filter an
Iterable into a Pair of Iterable's. |
static Iterable<Integer> |
rangeTo(int start,
int end)
Creates a sequence of
integers from start up to and
including end. |
static Iterable<Integer> |
rangeTo(int start,
int end,
int step)
Creates a sequence of
integers from start up to and
including end with the the supplied step between them. |
static Iterable<Integer> |
rangeUntil(int start,
int end)
Creates a sequence of
integers from start up to but not
including end. |
static Iterable<Integer> |
rangeUntil(int start,
int end,
int step)
Creates a sequence of
integers from start up to but not
including end with the the supplied step between them. |
static <A,B> Iterable<B> |
revMap(Iterable<? extends Function<A,B>> fs,
A arg)
Applies each function in
fs to arg. |
static <A> int |
size(Iterable<A> as)
Return the size of an iterable.
|
static <A> Iterable<A> |
take(int n,
Iterable<A> as)
Aakes the first
n as and returns them. |
static <A> Iterable<A> |
takeWhile(Iterable<A> as,
Predicate<A> p)
Return a new iterable containing only the first elements of
as for
which p#test returns true. |
static <A,B> Iterable<B> |
transform(Iterable<A> as,
Function<? super A,? extends B> f)
Deprecated.
function provided to make migration easier prefer to use #map
where possible
|
static <A,B> Iterable<A> |
unfold(Function<? super B,Option<Pair<A,B>>> f,
B seed)
Builds an Iterable from a seed value until
f returns none()
. |
static <A,B> Pair<Iterable<A>,Iterable<B>> |
unzip(Iterable<Pair<A,B>> pairs)
|
static <A,B> Iterable<Pair<A,B>> |
zip(Iterable<A> as,
Iterable<B> bs)
Zips two iterables into a single iterable that produces
pairs. |
static <A,B,C> BiFunction<Iterable<A>,Iterable<B>,Iterable<C>> |
zipWith(BiFunction<A,B,C> f)
Takes a two-arg function that returns a third type and reurn a new function
that takes iterables of the two input types and combines them into a new
iterable.
|
static <A> Iterable<Pair<A,Integer>> |
zipWithIndex(Iterable<A> as)
Takes an Iterable, and returns an Iterable of a Pair of the original
element and its index starting at zero.
|
public static <T> Iterable<T> emptyIterable()
Iterable with an
Iterator for which hasNext() always returns false,
and the other methods throw appropriate exceptions if called.
Intended to be used as a more idiomatic replacement for
Collections.emptyList() in code that otherwise deals only with
iterables.T - the type@SafeVarargs public static <A> Iterable<A> iterable(A... as)
A - The type of the elementsas - the elements to iterate overpublic static <T> Option<T> findFirst(Iterable<? extends T> elements, Predicate<? super T> p)
T - the typeelements - the iterable to search for a matching elementp - the predicate to use to determine if an element is eligible to be
returnedpublic static <A> Function<Iterable<A>,Option<A>> findFirst(Predicate<? super A> predicate)
findFirst(Iterable, Predicate) returning a function that takes an
Iterable as its argumentA - the typepredicate - the predicate to use to determine if an element is
eligible to be returnedIterable as its
argument, and returns the first element that satisfies the predicatepublic static <A> Option<A> first(Iterable<A> as)
as is empty, returns none(). Otherwise, returns
some(get(as, 0)).A - type of elements in asas - elements to get the first value of, must not be nullnone() if as is empty. some(get(as, 0))
otherwisepublic static <A,B> Iterable<B> ap(Iterable<A> as, Iterable<Function<A,B>> fs)
as - an iterablefs - The iterable of functions to apply.public static <A,B> Iterable<B> flatMap(Iterable<A> collection, Function<? super A,? extends Iterable<? extends B>> f)
f to each element of collection, then concatenates
the result.A - type of elements in collectionB - type elements in the new Iterable f will
transform elements tocollection - elements to apply f tof - Function to apply to elements of collectionf to each element of
collectionpublic static <A,B> Iterable<B> revMap(Iterable<? extends Function<A,B>> fs, A arg)
fs to arg.A - the argument typeB - the function output and type of the elements of the final
iterable.fs - an iterable of functions that the arg will be applied toarg - the argument to apply to the functionspublic static Predicate<Iterable<?>> isEmpty()
Predicate which checks if an Iterable is emptypublic static <A,B> Iterable<B> collect(Iterable<? extends A> from, Function<? super A,Option<B>> partial)
A - the input typeB - the output typefrom - the input iterable, must not be null and must not contain nullpartial - the collecting functionpublic static <T,A,R> R collect(Iterable<T> elements, Collector<T,A,R> collector)
T - the type of elements in the original IterableA - accumulator typeR - return typeelements - the iterable to run the Collector on. Can not be null.collector - the Collector. Can not be null.Collectorjavadocs for more details on how to use Collectors.public static <A> Pair<Iterable<A>,Iterable<A>> partition(Iterable<A> iterable, Predicate<? super A> p)
Iterable into a Pair of Iterable's.A - the typeiterable - to be filteredp - to filter each elementpublic static <A> Iterable<A> take(int n, Iterable<A> as)
n as and returns them.A - type of asn - number of as to take, must greater than or equal to zeroas - list of values, must not be null and must not contain nulln aspublic static <A> Iterable<A> drop(int n, Iterable<A> as)
n as and return the rest.A - type of asn - number of as to drop, must greater than or equal to zeroas - list of values, must not be null and must not contain nullas after dropping the first npublic static <A> Iterable<A> dropWhile(Iterable<A> as, Predicate<A> p)
as until an element returns false for
p#testA - type of asas - iterable to remove the first elements of as, must not be
nullp - predicate used to test which elements to drop from the iterable,
must not be nullas after removing the starting
elements that for which p#test returns trueto remove the first n elementspublic static <A> Iterable<A> takeWhile(Iterable<A> as, Predicate<A> p)
as for
which p#test returns true.A - type of asas - iterable to source the first elements of as, must not be
nullp - predicate used to test which elements to include in the new
iterable, must not be nullas starting from the
first element of as until p#test returns falseto take only the first n elementspublic static <A,B> Iterable<Pair<A,B>> zip(Iterable<A> as, Iterable<B> bs)
pairs.
See unzip(Iterable) for the opposite operationA - LHS typeB - RHS typeas - left valuesbs - right valuesiterable of pairs, only as long as the shortest
input iterable.public static <A,B,C> BiFunction<Iterable<A>,Iterable<B>,Iterable<C>> zipWith(BiFunction<A,B,C> f)
A - LHS typeB - RHS typeC - result typef - combiner function, must not be nullpublic static <A> Iterable<Pair<A,Integer>> zipWithIndex(Iterable<A> as)
A - the typeas - the original iterablepublic static Iterable<Integer> rangeUntil(int start, int end)
integers from start up to but not
including end.start - from (inclusive)end - to (exclusive)integerspublic static Iterable<Integer> rangeUntil(int start, int end, int step)
integers from start up to but not
including end with the the supplied step between them.start - from (inclusive)end - to (exclusive)step - size to step – must not be zero, must be positive if end is
greater than start, neagtive otherwiseintegerspublic static Iterable<Integer> rangeTo(int start, int end)
integers from start up to and
including end.start - from (inclusive)end - to (inclusive)integerspublic static Iterable<Integer> rangeTo(int start, int end, int step)
integers from start up to and
including end with the the supplied step between them.start - from (inclusive), must be greater than zero and less than endend - to (inclusive)step - size to step – must not be zero, must be positive if end is
greater than start, negative otherwiseintegerspublic static <A> Iterable<A> intersperse(Iterable<? extends A> as, A a)
A - the type of the elements.as - the source iterable.a - the element to intersperse between the source elements.public static <A> Iterable<A> intersperse(Iterable<? extends A> as, Supplier<A> a)
A - the type of the elements.as - the source iterable.a - the supplier of elements to intersperse between the source
elements.public static <A> int size(Iterable<A> as)
A - element typeas - iterable to compute the size of@Deprecated public static <A,B> Iterable<B> transform(Iterable<A> as, Function<? super A,? extends B> f)
A - original iterable typeB - output iterable typeas - the source iterablef - function to apply to all the elements of aspublic static <A,B> Iterable<B> map(Iterable<A> as, Function<? super A,? extends B> f)
A - original iterable typeB - output iterable typeas - the source iterablef - function to apply to all the elements of aspublic static <A> Iterable<A> filter(Iterable<A> as, Predicate<? super A> p)
A - element typeas - original iterablep - predicate to filter bypublic static <A> Iterable<A> join(Iterable<? extends Iterable<? extends A>> ias)
A - element typeias - one or more iterable to merge into the final iterable result,
must not be null and must not return null@SafeVarargs public static <A> Iterable<A> concat(Iterable<? extends A>... as)
A - super type of contained by all input iterablesas - any number of iterables containing Apublic static <A> boolean any(Iterable<? extends A> as, Predicate<? super A> p)
A - type of elements inside the input iterableas - iterable to compare for matching elementsp - predicate to test for matching elementspublic static <A> boolean all(Iterable<? extends A> as, Predicate<? super A> p)
A - type of elements inside the input iterableas - iterable to compare for matching elementsp - predicate to test for matching elementspublic static <A> Iterable<A> iterate(Function<? super A,? extends A> f, A start)
A - type of the elementsf - The iteration function, must not return nullstart - The value to begin iterating from.f to
start.public static <A,B> Iterable<A> unfold(Function<? super B,Option<Pair<A,B>>> f, B seed)
f returns none()
.A - type of the returned elements.B - type of the elements for which f is applied.f - The function that returns some(pair(a, b)), in which case
a is the next element of the resulting Iterable and b is
used as the input value for the next call of f, or none()
if it is done producing the elements. f must not be null and must not
return a pair containing null.seed - The start value to begin the unfold.public static <A extends Comparable<A>> Iterable<A> mergeSorted(Iterable<? extends Iterable<A>> xss)
A - collection typexss - collection of already sorted collections, must not be null and
must not return nullxss merged in a sorted orderpublic static <A> Iterable<A> mergeSorted(Iterable<? extends Iterable<A>> xss, Comparator<A> ordering)
A - type of the elementsxss - already sorted collection of collections, must not be null and
must not return nullordering - ordering to use when comparing elements, must not be nullxss merged in a sorted orderpublic static <A> boolean addAll(Collection<A> collectionToModify, Iterable<? extends A> elementsToAdd)
A - element typecollectionToModify - collection to add elements toelementsToAdd - source of addtional elements@SafeVarargs public static <A> Iterable<A> cycle(A... as)
A - returned elementsas - input values to cycle throughpublic static <A> Iterable<A> cycle(Iterable<? extends A> as)
A - returned elementsas - input values to cycle through must not be nullpublic static <A> String makeString(Iterable<? extends A> as, String start, String sep, String end, int maxLength)
A - type of the elements in the iterableas - the iterable to print must not be nullstart - prefix to start the printing withsep - separator to use between each elementend - suffic to end the printing withmaxLength - limit the length of the resulting stringpublic static <A> String makeString(Iterable<? extends A> as, String start, String sep, String end)
A - type of the elements in the iterableas - the iterable to print must not be nullstart - prefix to start the printing withsep - separator to use between each elementend - suffic to end the printing withpretty print
iterable with a custom lengthCopyright © 2018 Atlassian. All rights reserved.