edu.rice.cs.plt.iter
Class IterUtil

java.lang.Object
  extended by edu.rice.cs.plt.iter.IterUtil

public final class IterUtil
extends Object

A collection of static methods operating on iterables and iterators.

Most classes instantiated by these methods are serializable. However, since the classes generally wrap other objects, those objects must be serializable in order for serialization to succeed.


Method Summary
static
<T> boolean
and(Iterable<? extends T> iter, Predicate<? super T> pred)
          Check whether the given predicate holds for all values in iter.
static
<T1,T2,T3,T4>
boolean
and(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Iterable<? extends T4> iter4, Predicate4<? super T1,? super T2,? super T3,? super T4> pred)
          Check whether the given predicate holds for all corresponding values in the given iterables.
static
<T1,T2,T3> boolean
and(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Predicate3<? super T1,? super T2,? super T3> pred)
          Check whether the given predicate holds for all corresponding values in the given iterables.
static
<T1,T2> boolean
and(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Predicate2<? super T1,? super T2> pred)
          Check whether the given predicate holds for all corresponding values in iter1 and iter2.
static SizedIterable<?> arrayAsIterable(Object array)
          Returns an iterable that traverses the given array, which may contain primitives or references.
static SizedIterable<Boolean> arraySegment(boolean[] array, int start)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Boolean> arraySegment(boolean[] array, int start, int end)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Byte> arraySegment(byte[] array, int start)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Byte> arraySegment(byte[] array, int start, int end)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Character> arraySegment(char[] array, int start)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Character> arraySegment(char[] array, int start, int end)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Double> arraySegment(double[] array, int start)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Double> arraySegment(double[] array, int start, int end)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Float> arraySegment(float[] array, int start)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Float> arraySegment(float[] array, int start, int end)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Integer> arraySegment(int[] array, int start)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Integer> arraySegment(int[] array, int start, int end)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Long> arraySegment(long[] array, int start)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Long> arraySegment(long[] array, int start, int end)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Short> arraySegment(short[] array, int start)
          Create a SizedIterable wrapping a segment of the given array.
static SizedIterable<Short> arraySegment(short[] array, int start, int end)
          Create a SizedIterable wrapping a segment of the given array.
static
<T> SizedIterable<T>
arraySegment(T[] array, int start)
          Create a SizedIterable wrapping a segment of the given array.
static
<T> SizedIterable<T>
arraySegment(T[] array, int start, int end)
          Create a SizedIterable wrapping a segment of the given array.
static
<T> Enumeration<T>
asEnumeration(Iterator<? extends T> iter)
          Make an Enumeration based on the given Iterator.
static SizedIterable<Boolean> asIterable(boolean[] array)
          Create a SizedIterable wrapping the given array.
static SizedIterable<Byte> asIterable(byte[] values)
          Create a SizedIterable wrapping the given array.
static SizedIterable<Character> asIterable(char[] array)
          Create a SizedIterable wrapping the given array.
static SizedIterable<Character> asIterable(CharSequence sequence)
          Create an iterable that wraps the given CharSequence.
static SizedIterable<Double> asIterable(double[] values)
          Create a SizedIterable wrapping the given array.
static SizedIterable<Float> asIterable(float[] values)
          Create a SizedIterable wrapping the given array.
static SizedIterable<Integer> asIterable(int[] values)
          Create a SizedIterable wrapping the given array.
static SizedIterable<Long> asIterable(long[] values)
          Create a SizedIterable wrapping the given array.
static SizedIterable<Short> asIterable(short[] values)
          Create a SizedIterable wrapping the given array.
static SizedIterable<Character> asIterable(String sequence)
          Create an iterable that wraps the given string.
static
<T> SizedIterable<T>
asIterable(T... array)
          Create a SizedIterable wrapping the given array.
static
<T> ReadOnlyIterator<T>
asIterator(Enumeration<? extends T> en)
          Make an iterator based on a (legacy-style) Enumeration.
static ReadOnlyIterator<Byte> asIterator(InputStream in)
          Make an iterator based on an InputStream.
static ReadOnlyIterator<Character> asIterator(Reader in)
          Make an iterator based on a Reader.
static ReadOnlyIterator<String> asIterator(StringTokenizer s)
          Make an iterator based on a StringTokenizer.
static
<T> SizedIterable<T>
asSizedIterable(Collection<T> coll)
          Convert the given Collection to a SizedIterable.
static
<T> CollapsedIterable<T>
collapse(Iterable<? extends Iterable<? extends T>> iters)
          Collapse a list of lists into a single list.
static
<T> ComposedIterable<T>
compose(Iterable<? extends T> i1, Iterable<? extends T> i2)
          Create a ComposedIterable with the given arguments.
static
<T> ComposedIterable<T>
compose(Iterable<? extends T> rest, T last)
          Create a ComposedIterable with the given arguments.
static
<T> ComposedIterable<T>
compose(T first, Iterable<? extends T> rest)
          Create a ComposedIterable with the given arguments.
static
<T> Lambda2<Iterable<? extends T>,Iterable<? extends T>,Iterable<T>>
composeLambda()
          Produce a lambda that invokes compose(Object, Iterable).
static
<T> Lambda2<T,Iterable<? extends T>,Iterable<T>>
composeLeftLambda()
          Produce a lambda that invokes compose(Object, Iterable).
static
<T> Lambda2<Iterable<? extends T>,T,Iterable<T>>
composeRightLambda()
          Produce a lambda that invokes compose(Iterable, Object).
static
<T> Iterable<T>
conditionalSnapshot(Iterable<T> iter, int threshold)
          Produce a snapshot of iter if its composite size is greater than the given threshold.
static boolean contains(Iterable<?> iter, Object o)
          Test whether the given object appears in an iteration of iter.
static boolean containsAll(Iterable<?> iter, Iterable<?> subset)
          Test whether the given objects all appear in when iterating over iter.
static boolean containsAny(Iterable<?> iter, Iterable<?> candidates)
          Test whether one of the given objects appears in an iteration of iter.
static
<T> FiniteSequenceIterable<T>
copy(T value, int copies)
          Create a sequence containing copies instances of the given value.
static
<T> SizedIterable<Iterable<T>>
cross(Iterable<? extends Iterable<? extends T>> iters)
          Lazily produce the cartesian (cross) product of an arbitrary number of iterables.
static
<T1,T2> SizedIterable<Pair<T1,T2>>
cross(Iterable<? extends T1> left, Iterable<? extends T2> right)
          Lazily produce the cartesian (cross) product of two iterables, wrapping each combination of elements in a Pair.
static
<T1,T2,T3> SizedIterable<Triple<T1,T2,T3>>
cross(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3)
          Lazily produce the cartesian (cross) product of three iterables, wrapping each combination of elements in a Triple.
static
<T1,T2,T3,T4>
SizedIterable<Quad<T1,T2,T3,T4>>
cross(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Iterable<? extends T4> iter4)
          Lazily produce the cartesian (cross) product of four iterables, wrapping each combination of elements in a Quad.
static
<T1,T2,T3,T4,R>
SizedIterable<R>
cross(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Iterable<? extends T4> iter4, Lambda4<? super T1,? super T2,? super T3,? super T4,? extends R> combiner)
          Lazily produce the cartesian (cross) product of four iterables.
static
<T1,T2,T3,R>
SizedIterable<R>
cross(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Lambda3<? super T1,? super T2,? super T3,? extends R> combiner)
          Lazily produce the cartesian (cross) product of three iterables.
static
<T1,T2,R> SizedIterable<R>
cross(Iterable<? extends T1> left, Iterable<? extends T2> right, Lambda2<? super T1,? super T2,? extends R> combiner)
          Lazily produce the cartesian (cross) product of two iterables.
static
<T,R> SizedIterable<R>
crossFold(Iterable<? extends Iterable<? extends T>> iters, R base, Lambda2<? super R,? super T,? extends R> combiner)
          Lazily apply the given folding function to each tuple in the cartesian (cross) product of the given iterables.
static
<T> SizedIterable<Iterable<T>>
diagonalCross(Iterable<? extends Iterable<? extends T>> iters)
          Lazily produce the cartesian (cross) product of an arbitrary number of iterables.
static
<T1,T2> SizedIterable<Pair<T1,T2>>
diagonalCross(Iterable<? extends T1> left, Iterable<? extends T2> right)
          Lazily produce the cartesian (cross) product of two iterables, wrapping each combination of elements in a Pair.
static
<T1,T2,T3> SizedIterable<Triple<T1,T2,T3>>
diagonalCross(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3)
          Lazily produce the cartesian (cross) product of three iterables, wrapping each combination of elements in a Triple.
static
<T1,T2,T3,T4>
SizedIterable<Quad<T1,T2,T3,T4>>
diagonalCross(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Iterable<? extends T4> iter4)
          Lazily produce the cartesian (cross) product of four iterables, wrapping each combination of elements in a Quad.
static
<T1,T2,T3,T4,R>
SizedIterable<R>
diagonalCross(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Iterable<? extends T4> iter4, Lambda4<? super T1,? super T2,? super T3,? super T4,? extends R> combiner)
          Lazily produce the cartesian (cross) product of four iterables.
static
<T1,T2,T3,R>
SizedIterable<R>
diagonalCross(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Lambda3<? super T1,? super T2,? super T3,? extends R> combiner)
          Lazily produce the cartesian (cross) product of three iterables.
static
<T1,T2,R> SizedIterable<R>
diagonalCross(Iterable<? extends T1> left, Iterable<? extends T2> right, Lambda2<? super T1,? super T2,? extends R> combiner)
          Lazily produce the cartesian (cross) product of two iterables.
static
<T,R> SizedIterable<R>
diagonalCrossFold(Iterable<? extends Iterable<? extends T>> iters, R base, Lambda2<? super R,? super T,? extends R> combiner)
          Lazily apply the given folding function to each tuple in the cartesian (cross) product of the given iterables.
static
<T1,A,S2> Iterable<S2>
distribute(Iterable<? extends T1> original, Lambda<? super T1,? extends Iterable<? extends A>> breakT, Lambda<? super Iterable<A>,? extends S2> makeS)
          Use the cross(Iterable) function to lazily apply a distribution rule to the given composite object list.
static
<S1,T1,A,S2,T2>
T2
distribute(S1 original, Lambda<? super S1,? extends Iterable<? extends T1>> breakS, Lambda<? super T1,? extends Iterable<? extends A>> breakT, Lambda<? super Iterable<A>,? extends S2> makeS, Lambda<? super Iterable<S2>,? extends T2> makeT)
          Use the cross(Iterable) function to apply a distribution rule to the given composite object.
static
<T> EmptyIterable<T>
empty()
          Create an EmptyIterable; equivalent to make().
static
<T> FilteredIterable<T>
filter(Iterable<? extends T> iter, Predicate<? super T> pred)
          Produce an iterable that only contains values from the given iterable that satisfy a predicate.
static
<T> FilteredIterable<T>
filterInstances(Iterable<? super T> iter, Class<? extends T> c)
          Cast all instances of the given type appropriately; filter out any non-instances.
static
<T> SnapshotIterable<T>
filterSnapshot(Iterable<? extends T> iter, Predicate<? super T> pred)
          Produce an iterable that only contains values from the given iterable that satisfy a predicate.
static
<T> FiniteSequenceIterable<T>
finiteSequence(T initial, Lambda<? super T,? extends T> successor, int size)
          Create a finite sequence of the given size defined by an initial value and a successor function.
static
<T> T
first(Iterable<? extends T> iter)
          Access the first value in the given iterable.
static
<T,R> R
fold(Iterable<? extends T> iter, R base, Lambda2<? super R,? super T,? extends R> combiner)
          Compute the left fold of the given list.
static boolean hasFixedSize(Iterable<?> iter)
          Return true iff the given iterable is known to have a fixed size.
static int hashCode(Iterable<?> iter)
          Return a hash code computed by xoring shifted copies of each element's hash code; the result is consistent with isEqual(java.lang.Iterable, java.lang.Iterable), but may not be consistent with the input's equals and hashCode methods; invokes RecurUtil#safeHashCode(Object) on each element.
static
<T> ImmutableIterable<T>
immutable(Iterable<? extends T> iter)
          Produce an ImmutableIterable with the given iterable.
static
<T> SequenceIterable<T>
infiniteSequence(T initial, Lambda<? super T,? extends T> successor)
          Create an infinite sequence defined by an initial value and a successor function.
static FiniteSequenceIterable<Integer> integerSequence(int start, int end)
          Create a simple sequence containing the numbers between start and end (inclusive).
static boolean isEmpty(Iterable<?> iter)
           
static boolean isEqual(Iterable<?> iter1, Iterable<?> iter2)
          Return true iff the lists are identical (according to ==), or they have the same size (according to sizeOf(java.lang.Iterable)) and each corresponding element is equal (according to LambdaUtil.EQUAL).
static boolean isInfinite(Iterable<?> iter)
          Return true iff the given iterable is known to have an infinite size.
static boolean isStatic(Iterable<?> iter)
          Return true iff the given iterable is known to be immutable.
static
<T> T
last(Iterable<? extends T> iter)
          Access the last value in the given iterable.
static
<T> SizedIterable<T>
make()
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T... vals)
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T v1)
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T[] vals, int start)
          Create an immutable SizedIterable containing the given values, from index start through the end of the array.
static
<T> SizedIterable<T>
make(T[] vals, int start, int end)
          Create an immutable SizedIterable containing the given values, from array index start through end-1, inclusive (the size of the result is end-start).
static
<T> SizedIterable<T>
make(T v1, T v2)
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T v1, T v2, T v3)
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T v1, T v2, T v3, T v4)
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T v1, T v2, T v3, T v4, T v5)
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T v1, T v2, T v3, T v4, T v5, T v6)
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T v1, T v2, T v3, T v4, T v5, T v6, T v7)
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8)
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8, T v9)
          Create an immutable SizedIterable containing the given values.
static
<T> SizedIterable<T>
make(T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8, T v9, T v10)
          Create an immutable SizedIterable containing the given values.
static
<T> Octet<T,T,T,T,T,T,T,T>
makeOctet(Iterable<? extends T> iter)
          Convert an iterable of 8 elements to an Octet.
static
<T> Option<T>
makeOption(Iterable<? extends T> iter)
          Convert an iterable of 0 or 1 elements to an Option.
static
<T> Pair<T,T>
makePair(Iterable<? extends T> iter)
          Convert an iterable of 2 elements to a Pair.
static
<T> Quad<T,T,T,T>
makeQuad(Iterable<? extends T> iter)
          Convert an iterable of 4 elements to a Quad.
static
<T> Quint<T,T,T,T,T>
makeQuint(Iterable<? extends T> iter)
          Convert an iterable of 5 elements to a Quint.
static
<T> Septet<T,T,T,T,T,T,T>
makeSeptet(Iterable<? extends T> iter)
          Convert an iterable of 7 elements to a Septet.
static
<T> Sextet<T,T,T,T,T,T>
makeSextet(Iterable<? extends T> iter)
          Convert an iterable of 6 elements to a Sextet.
static
<T> Triple<T,T,T>
makeTriple(Iterable<? extends T> iter)
          Convert an iterable of 3 elements to a Triple.
static
<T> Wrapper<T>
makeWrapper(Iterable<? extends T> iter)
          Convert an iterable of 1 element to a Wrapper.
static
<T,R> SizedIterable<R>
map(Iterable<? extends T> source, Lambda<? super T,? extends R> map)
          Lazily apply a map function to each element in an iterable.
static
<T1,T2,T3,T4,R>
SizedIterable<R>
map(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Iterable<? extends T4> iter4, Lambda4<? super T1,? super T2,? super T3,? super T4,? extends R> map)
          Lazily apply a map function to each corresponding quadruple of elements in the given iterables.
static
<T1,T2,T3,R>
SizedIterable<R>
map(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Lambda3<? super T1,? super T2,? super T3,? extends R> map)
          Lazily apply a map function to each corresponding triple of elements in the given iterables.
static
<T1,T2,R> SizedIterable<R>
map(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Lambda2<? super T1,? super T2,? extends R> map)
          Lazily apply a map function to each corresponding pair of elements in the given iterables.
static
<T,R> SnapshotIterable<R>
mapSnapshot(Iterable<? extends T> source, Lambda<? super T,? extends R> map)
          Immediately apply a map function to each element in an iterable.
static
<T1,T2,T3,T4,R>
SnapshotIterable<R>
mapSnapshot(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Iterable<? extends T4> iter4, Lambda4<? super T1,? super T2,? super T3,? super T4,? extends R> map)
          Immediately apply a map function to each corresponding quadruple of elements in the given iterables.
static
<T1,T2,T3,R>
SnapshotIterable<R>
mapSnapshot(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Lambda3<? super T1,? super T2,? super T3,? extends R> map)
          Immediately apply a map function to each corresponding triple of elements in the given iterables.
static
<T1,T2,R> SnapshotIterable<R>
mapSnapshot(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Lambda2<? super T1,? super T2,? extends R> map)
          Immediately apply a map function to each corresponding pair of elements in the given iterables.
static String multilineToString(Iterable<?> iter)
          Generate a string representation of the given iterable where each element is listed on a separate line.
static
<T> boolean
or(Iterable<? extends T> iter, Predicate<? super T> pred)
          Check whether the given predicate holds for some value in iter.
static
<T1,T2,T3,T4>
boolean
or(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Iterable<? extends T4> iter4, Predicate4<? super T1,? super T2,? super T3,? super T4> pred)
          Check whether the given predicate holds for some corresponding values in the given iterables.
static
<T1,T2,T3> boolean
or(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Predicate3<? super T1,? super T2,? super T3> pred)
          Check whether the given predicate holds for some corresponding values in the given iterables.
static
<T1,T2> boolean
or(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Predicate2<? super T1,? super T2> pred)
          Check whether the given predicate holds for some corresponding values in iter1 and iter2.
static
<T> SizedIterable<T>
pairFirsts(Iterable<? extends Pair<? extends T,?>> iter)
          Lazily create an iterable containing the first values of the given tuples.
static
<T> SizedIterable<T>
pairSeconds(Iterable<? extends Pair<?,? extends T>> iter)
          Lazily create an iterable containing the second values of the given tuples.
static
<T> SizedIterable<T>
quadFirsts(Iterable<? extends Quad<? extends T,?,?,?>> iter)
          Lazily create an iterable containing the first values of the given tuples.
static
<T> SizedIterable<T>
quadFourths(Iterable<? extends Quad<?,?,?,? extends T>> iter)
          Lazily create an iterable containing the fourth values of the given tuples.
static
<T> SizedIterable<T>
quadSeconds(Iterable<? extends Quad<?,? extends T,?,?>> iter)
          Lazily create an iterable containing the second values of the given tuples.
static
<T> SizedIterable<T>
quadThirds(Iterable<? extends Quad<?,?,? extends T,?>> iter)
          Lazily create an iterable containing the third values of the given tuples.
static
<T> SizedIterable<T>
relax(Iterable<? extends T> iter)
          Allow covariance in situations where wildcards can't be used by wrapping the iterable with a less- precise type parameter.
static
<T> Iterator<T>
relax(Iterator<? extends T> iter)
          Allow covariance in situations where wildcards can't be used by wraping the iterator with a less- precise type parameter.
static
<T> SizedIterable<T>
reverse(Iterable<? extends T> iter)
          Produce a reverse-order iterable over the given elements.
static
<T> void
run(Iterable<? extends T> iter, Runnable1<? super T> runnable)
          Apply the given runnable to every element in an iterable.
static
<T1,T2,T3,T4>
void
run(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Iterable<? extends T4> iter4, Runnable4<? super T1,? super T2,? super T3,? super T4> runnable)
          Apply the given runnable to every quadruple of corresponding elements in the given iterables.
static
<T1,T2,T3> void
run(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Runnable3<? super T1,? super T2,? super T3> runnable)
          Apply the given runnable to every triple of corresponding elements in the given iterables.
static
<T1,T2> void
run(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Runnable2<? super T1,? super T2> runnable)
          Apply the given runnable to every pair of corresponding elements in the given iterables.
static
<T> SizedIterable<T>
shuffle(Iterable<T> iter)
          Produce a shuffled iterable over the given elements.
static
<T> SizedIterable<T>
shuffle(Iterable<T> iter, Random random)
          Produce a shuffled iterable over the given elements, using the specified random number generator.
static
<T> SingletonIterable<T>
singleton(T value)
          Create a SingletonIterable; equivalent to make(Object).
static int sizeOf(Iterable<?> iter)
          Compute the size of the given iterable.
static int sizeOf(Iterable<?> iter, int bound)
          Compute the size of the given iterable, or bound -- whichever is less.
static
<T> SkipFirstIterable<T>
skipFirst(Iterable<T> iter)
          Produce an iterable that skips the first element of iter (if it exists)
static
<T> SkipLastIterable<T>
skipLast(Iterable<? extends T> iter)
          Produce an iterable that skips the last element of iter (if it exists).
static
<T> SnapshotIterable<T>
snapshot(Iterable<? extends T> iter)
          Create a SnapshotIterable with the given iterable.
static
<T> SnapshotIterable<T>
snapshot(Iterator<? extends T> iter)
          Create a SnapshotIterable with the given iterator.
static
<T extends Comparable<? super T>>
SizedIterable<T>
sort(Iterable<T> iter)
          Produce a sorted iterable over the given elements.
static
<T> SizedIterable<T>
sort(Iterable<T> iter, Comparator<? super T> comp)
          Produce a sorted iterable over the given elements, using the specified comparator.
static
<T> Pair<SizedIterable<T>,SizedIterable<T>>
split(Iterable<? extends T> iter, int index)
          Split the given iterable into two at the given index.
static
<T> T[]
toArray(Iterable<? extends T> iter, Class<T> type)
          Make an array with the given elements.
static
<T> SizedIterable<T>
toIterable(Octet<? extends T,? extends T,? extends T,? extends T,? extends T,? extends T,? extends T,? extends T> tuple)
          Produce an iterable of size 8 from an Octet.
static
<T> SizedIterable<T>
toIterable(Option<? extends T> option)
          Produce an iterable of size 0 or 1 from an Option.
static
<T> SizedIterable<T>
toIterable(Pair<? extends T,? extends T> tuple)
          Produce an iterable of size 2 from a Pair.
static
<T> SizedIterable<T>
toIterable(Quad<? extends T,? extends T,? extends T,? extends T> tuple)
          Produce an iterable of size 4 from a Quad.
static
<T> SizedIterable<T>
toIterable(Quint<? extends T,? extends T,? extends T,? extends T,? extends T> tuple)
          Produce an iterable of size 5 from a Quint.
static
<T> SizedIterable<T>
toIterable(Septet<? extends T,? extends T,? extends T,? extends T,? extends T,? extends T,? extends T> tuple)
          Produce an iterable of size 7 from a Septet.
static
<T> SizedIterable<T>
toIterable(Sextet<? extends T,? extends T,? extends T,? extends T,? extends T,? extends T> tuple)
          Produce an iterable of size 6 from a Sextet.
static
<T> SizedIterable<T>
toIterable(Triple<? extends T,? extends T,? extends T> tuple)
          Produce an iterable of size 3 from a Triple.
static
<T> SizedIterable<T>
toIterable(Wrapper<? extends T> tuple)
          Produce an iterable of size 1 from a Wrapper.
static String toString(Iterable<?> iter)
          Generate a string representation of the given iterable, matching the Collection conventions (results like "[foo, bar, baz]").
static String toString(Iterable<?> iter, String prefix, String delimiter, String suffix)
          Generate a string representation of the given iterable beginning with prefix, ending with suffix, and delimited by delimiter.
static
<T> SizedIterable<T>
tripleFirsts(Iterable<? extends Triple<? extends T,?,?>> iter)
          Lazily create an iterable containing the first values of the given tuples.
static
<T> SizedIterable<T>
tripleSeconds(Iterable<? extends Triple<?,? extends T,?>> iter)
          Lazily create an iterable containing the second values of the given tuples.
static
<T> SizedIterable<T>
tripleThirds(Iterable<? extends Triple<?,?,? extends T>> iter)
          Lazily create an iterable containing the third values of the given tuples.
static
<T> TruncatedIterable<T>
truncate(Iterable<? extends T> iter, int size)
          Truncate the given iterable.
static
<T,R> Iterable<R>
valuesOf(Iterable<? extends Lambda<? super T,? extends R>> iter, T arg)
          Lazily create an iterable containing the values of the application of the given lambdas.
static
<T1,T2,R> SizedIterable<R>
valuesOf(Iterable<? extends Lambda2<? super T1,? super T2,? extends R>> iter, T1 arg1, T2 arg2)
          Lazily create an iterable containing the values of the application of the given lambdas.
static
<T1,T2,T3,R>
SizedIterable<R>
valuesOf(Iterable<? extends Lambda3<? super T1,? super T2,? super T3,? extends R>> iter, T1 arg1, T2 arg2, T3 arg3)
          Lazily create an iterable containing the values of the application of the given lambdas.
static
<R> SizedIterable<R>
valuesOf(Iterable<? extends Thunk<? extends R>> iter)
          Lazily create an iterable containing the values of the given thunks.
static
<T1,T2> SizedIterable<Pair<T1,T2>>
zip(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2)
          Lazily create an iterable of Pairs of corresponding values from the given iterables (assumed to always have the same length).
static
<T1,T2,T3> SizedIterable<Triple<T1,T2,T3>>
zip(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3)
          Lazily create an iterable of Triples of corresponding values from the given iterables (assumed to always have the same length).
static
<T1,T2,T3,T4>
SizedIterable<Quad<T1,T2,T3,T4>>
zip(Iterable<? extends T1> iter1, Iterable<? extends T2> iter2, Iterable<? extends T3> iter3, Iterable<? extends T4> iter4)
          Lazily create an iterable of Quads of corresponding values from the given iterables (assumed to always have the same length).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isEmpty

public static boolean isEmpty(Iterable<?> iter)
Returns:
true iff the given iterable contains no elements

sizeOf

public static int sizeOf(Iterable<?> iter)
Compute the size of the given iterable. Where possible (when iter is a SizedIterable or a Collection), this is a potentially constant-time operation; otherwise, it is linear in the size of iter (if iter is infinite in this case, this method will loop Integer.MAX_VALUE times before returning).


sizeOf

public static int sizeOf(Iterable<?> iter,
                         int bound)
Compute the size of the given iterable, or bound -- whichever is less. This allows a size to be computed where the iterable may be infinite. Where possible (when iter is a SizedIterable or a Collection), this is a potentially constant-time operation; otherwise, it is linear in the size of iter or bound (whichever is smaller).


isInfinite

public static boolean isInfinite(Iterable<?> iter)
Return true iff the given iterable is known to have an infinite size.

See Also:
SizedIterable.isInfinite()

hasFixedSize

public static boolean hasFixedSize(Iterable<?> iter)
Return true iff the given iterable is known to have a fixed size. Infinite iterables are considered fixed if they will never become finite.

See Also:
SizedIterable.hasFixedSize()

isStatic

public static boolean isStatic(Iterable<?> iter)
Return true iff the given iterable is known to be immutable.

See Also:
SizedIterable.isStatic()

contains

public static boolean contains(Iterable<?> iter,
                               Object o)
Test whether the given object appears in an iteration of iter. Uses the Collection.contains(java.lang.Object) method where possible; otherwise, may take linear time.


containsAll

public static boolean containsAll(Iterable<?> iter,
                                  Iterable<?> subset)
Test whether the given objects all appear in when iterating over iter. Uses the Collection.containsAll(java.util.Collection) and Collection.contains(java.lang.Object) methods where possible; otherwise, may take quadratic time.

See Also:
CollectUtil.containsAll(java.util.Collection, java.lang.Iterable), and(java.lang.Iterable, edu.rice.cs.plt.lambda.Predicate)

containsAny

public static boolean containsAny(Iterable<?> iter,
                                  Iterable<?> candidates)
Test whether one of the given objects appears in an iteration of iter. Uses the Collection.contains(java.lang.Object) method where possible; otherwise, may take quadratic time.

See Also:
or(java.lang.Iterable, edu.rice.cs.plt.lambda.Predicate)

toString

public static String toString(Iterable<?> iter)
Generate a string representation of the given iterable, matching the Collection conventions (results like "[foo, bar, baz]"). Invokes RecurUtil.safeToString(Object) on each element. If the iterable is known to be infinite (isInfinite(java.lang.Iterable)), the string contains a few elements followed by "...".


multilineToString

public static String multilineToString(Iterable<?> iter)
Generate a string representation of the given iterable where each element is listed on a separate line. Invokes RecurUtil.safeToString(Object) on each element. If the iterable is known to be infinite (isInfinite(java.lang.Iterable)), the string contains a few elements followed by "...".


toString

public static String toString(Iterable<?> iter,
                              String prefix,
                              String delimiter,
                              String suffix)
Generate a string representation of the given iterable beginning with prefix, ending with suffix, and delimited by delimiter. Invokes RecurUtil.safeToString(Object) on each element. If the iterable is known to be infinite (isInfinite(java.lang.Iterable)), the string contains a few elements followed by "...".


isEqual

public static boolean isEqual(Iterable<?> iter1,
                              Iterable<?> iter2)
Return true iff the lists are identical (according to ==), or they have the same size (according to sizeOf(java.lang.Iterable)) and each corresponding element is equal (according to LambdaUtil.EQUAL). Assumes that at least one of the iterables is finite.


hashCode

public static int hashCode(Iterable<?> iter)
Return a hash code computed by xoring shifted copies of each element's hash code; the result is consistent with isEqual(java.lang.Iterable, java.lang.Iterable), but may not be consistent with the input's equals and hashCode methods; invokes RecurUtil#safeHashCode(Object) on each element. Assumes the iterable is finite.


asIterator

public static <T> ReadOnlyIterator<T> asIterator(Enumeration<? extends T> en)
Make an iterator based on a (legacy-style) Enumeration. If an Iterable is needed (rather than an Iterator), the result can be wrapped in a ReadOnceIterable.


asIterator

public static ReadOnlyIterator<String> asIterator(StringTokenizer s)
Make an iterator based on a StringTokenizer. (This is similar to asIterator(Enumeration), but allows the tokenizer to be treated as an enumeration of Strings rather than, as defined, an enumeration of Objects.) If an Iterable is needed (rather than an Iterator), the result can be wrapped in a ReadOnceIterable.


asIterator

public static ReadOnlyIterator<Character> asIterator(Reader in)
Make an iterator based on a Reader. If an IOException occurs while reading, an IllegalStateException is thrown. If an Iterable is needed (rather than an Iterator), the result can be wrapped in a ReadOnceIterable.


asIterator

public static ReadOnlyIterator<Byte> asIterator(InputStream in)
Make an iterator based on an InputStream. If an IOException occurs while reading, an IllegalStateException is thrown. If an Iterable is needed (rather than an Iterator), the result can be wrapped in a ReadOnceIterable.


asEnumeration

public static <T> Enumeration<T> asEnumeration(Iterator<? extends T> iter)
Make an Enumeration based on the given Iterator. For compatibility with legacy APIs.


empty

public static <T> EmptyIterable<T> empty()
Create an EmptyIterable; equivalent to make().


singleton

public static <T> SingletonIterable<T> singleton(T value)
Create a SingletonIterable; equivalent to make(Object).


compose

public static <T> ComposedIterable<T> compose(T first,
                                              Iterable<? extends T> rest)
Create a ComposedIterable with the given arguments.


composeLeftLambda

public static <T> Lambda2<T,Iterable<? extends T>,Iterable<T>> composeLeftLambda()
Produce a lambda that invokes compose(Object, Iterable).


compose

public static <T> ComposedIterable<T> compose(Iterable<? extends T> rest,
                                              T last)
Create a ComposedIterable with the given arguments.


composeRightLambda

public static <T> Lambda2<Iterable<? extends T>,T,Iterable<T>> composeRightLambda()
Produce a lambda that invokes compose(Iterable, Object).


compose

public static <T> ComposedIterable<T> compose(Iterable<? extends T> i1,
                                              Iterable<? extends T> i2)
Create a ComposedIterable with the given arguments.


composeLambda

public static <T> Lambda2<Iterable<? extends T>,Iterable<? extends T>,Iterable<T>> composeLambda()
Produce a lambda that invokes compose(Object, Iterable).


snapshot

public static <T> SnapshotIterable<T> snapshot(Iterable<? extends T> iter)
Create a SnapshotIterable with the given iterable.


snapshot

public static <T> SnapshotIterable<T> snapshot(Iterator<? extends T> iter)
Create a SnapshotIterable with the given iterator.


conditionalSnapshot

public static <T> Iterable<T> conditionalSnapshot(Iterable<T> iter,
                                                  int threshold)
Produce a snapshot of iter if its composite size is greater than the given threshold.

See Also:
ObjectUtil.compositeSize(java.lang.Object)

immutable

public static <T> ImmutableIterable<T> immutable(Iterable<? extends T> iter)
Produce an ImmutableIterable with the given iterable.


relax

public static <T> SizedIterable<T> relax(Iterable<? extends T> iter)
Allow covariance in situations where wildcards can't be used by wrapping the iterable with a less- precise type parameter.


relax

public static <T> Iterator<T> relax(Iterator<? extends T> iter)
Allow covariance in situations where wildcards can't be used by wraping the iterator with a less- precise type parameter.


make

public static <T> SizedIterable<T> make()
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T v1)
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T v1,
                                        T v2)
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T v1,
                                        T v2,
                                        T v3)
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T v1,
                                        T v2,
                                        T v3,
                                        T v4)
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T v1,
                                        T v2,
                                        T v3,
                                        T v4,
                                        T v5)
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T v1,
                                        T v2,
                                        T v3,
                                        T v4,
                                        T v5,
                                        T v6)
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T v1,
                                        T v2,
                                        T v3,
                                        T v4,
                                        T v5,
                                        T v6,
                                        T v7)
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T v1,
                                        T v2,
                                        T v3,
                                        T v4,
                                        T v5,
                                        T v6,
                                        T v7,
                                        T v8)
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T v1,
                                        T v2,
                                        T v3,
                                        T v4,
                                        T v5,
                                        T v6,
                                        T v7,
                                        T v8,
                                        T v9)
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T v1,
                                        T v2,
                                        T v3,
                                        T v4,
                                        T v5,
                                        T v6,
                                        T v7,
                                        T v8,
                                        T v9,
                                        T v10)
Create an immutable SizedIterable containing the given values.


make

public static <T> SizedIterable<T> make(T... vals)
Create an immutable SizedIterable containing the given values. Requires linear time to make a copy (necessary because vals can be mutated by the caller). Note that restrictions on array creation may lead to errors or warnings at the invocation site where T is a non-reifiable type.


make

public static <T> SizedIterable<T> make(T[] vals,
                                        int start)
Create an immutable SizedIterable containing the given values, from index start through the end of the array. Requires linear time to make a copy (necessary because vals can be mutated by the caller).


make

public static <T> SizedIterable<T> make(T[] vals,
                                        int start,
                                        int end)
Create an immutable SizedIterable containing the given values, from array index start through end-1, inclusive (the size of the result is end-start). Requires linear time to make a copy (necessary because vals can be mutated by the caller).


infiniteSequence

public static <T> SequenceIterable<T> infiniteSequence(T initial,
                                                       Lambda<? super T,? extends T> successor)
Create an infinite sequence defined by an initial value and a successor function.


finiteSequence

public static <T> FiniteSequenceIterable<T> finiteSequence(T initial,
                                                           Lambda<? super T,? extends T> successor,
                                                           int size)
Create a finite sequence of the given size defined by an initial value and a successor function.


integerSequence

public static FiniteSequenceIterable<Integer> integerSequence(int start,
                                                              int end)
Create a simple sequence containing the numbers between start and end (inclusive). start may be less than or greater than end (or even equal to it); the resulting iterator will increment or decrement as necessary.


copy

public static <T> FiniteSequenceIterable<T> copy(T value,
                                                 int copies)
Create a sequence containing copies instances of the given value.


asIterable

public static <T> SizedIterable<T> asIterable(T... array)
Create a SizedIterable wrapping the given array. Subsequent changes to the array will be reflected in the result. (If that is not the desired behavior, make a copy instead with make(Object[]).)


arraySegment

public static <T> SizedIterable<T> arraySegment(T[] array,
                                                int start)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through the end of the array are included. Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, make a copy instead with make(Object[], int).)

Throws:
IndexOutOfBoundsException - If start is an invalid index.

arraySegment

public static <T> SizedIterable<T> arraySegment(T[] array,
                                                int start,
                                                int end)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through end-1 are included (and the size is thus end-start). Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, make a copy instead with make(Object[], int, int).)

Throws:
IndexOutOfBoundsException - If start and end are inconsistent with each other or with the length of the array.

asIterable

public static SizedIterable<Boolean> asIterable(boolean[] array)
Create a SizedIterable wrapping the given array. Subsequent changes to the array will be reflected in the result. (If that is not the desired behavior, snapshot(Iterable) may be invoked on the result.)


arraySegment

public static SizedIterable<Boolean> arraySegment(boolean[] array,
                                                  int start)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through the end of the array are included. Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start is an invalid index.

arraySegment

public static SizedIterable<Boolean> arraySegment(boolean[] array,
                                                  int start,
                                                  int end)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through end-1 are included (and the size is thus end-start). Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start and end are inconsistent with each other or with the length of the array.

asIterable

public static SizedIterable<Character> asIterable(char[] array)
Create a SizedIterable wrapping the given array. Subsequent changes to the array will be reflected in the result. (If that is not the desired behavior, snapshot(Iterable) may be invoked on the result.)


arraySegment

public static SizedIterable<Character> arraySegment(char[] array,
                                                    int start)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through the end of the array are included. Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start is an invalid index.

arraySegment

public static SizedIterable<Character> arraySegment(char[] array,
                                                    int start,
                                                    int end)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through end-1 are included (and the size is thus end-start). Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start and end are inconsistent with each other or with the length of the array.

asIterable

public static SizedIterable<Byte> asIterable(byte[] values)
Create a SizedIterable wrapping the given array. Subsequent changes to the array will be reflected in the result. (If that is not the desired behavior, snapshot(Iterable) may be invoked on the result.)


arraySegment

public static SizedIterable<Byte> arraySegment(byte[] array,
                                               int start)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through the end of the array are included. Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start is an invalid index.

arraySegment

public static SizedIterable<Byte> arraySegment(byte[] array,
                                               int start,
                                               int end)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through end-1 are included (and the size is thus end-start). Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start and end are inconsistent with each other or with the length of the array.

asIterable

public static SizedIterable<Short> asIterable(short[] values)
Create a SizedIterable wrapping the given array. Subsequent changes to the array will be reflected in the result. (If that is not the desired behavior, snapshot(Iterable) may be invoked on the result.)


arraySegment

public static SizedIterable<Short> arraySegment(short[] array,
                                                int start)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through the end of the array are included. Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start is an invalid index.

arraySegment

public static SizedIterable<Short> arraySegment(short[] array,
                                                int start,
                                                int end)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through end-1 are included (and the size is thus end-start). Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start and end are inconsistent with each other or with the length of the array.

asIterable

public static SizedIterable<Integer> asIterable(int[] values)
Create a SizedIterable wrapping the given array. Subsequent changes to the array will be reflected in the result. (If that is not the desired behavior, snapshot(Iterable) may be invoked on the result.)


arraySegment

public static SizedIterable<Integer> arraySegment(int[] array,
                                                  int start)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through the end of the array are included. Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start is an invalid index.

arraySegment

public static SizedIterable<Integer> arraySegment(int[] array,
                                                  int start,
                                                  int end)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through end-1 are included (and the size is thus end-start). Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start and end are inconsistent with each other or with the length of the array.

asIterable

public static SizedIterable<Long> asIterable(long[] values)
Create a SizedIterable wrapping the given array. Subsequent changes to the array will be reflected in the result. (If that is not the desired behavior, snapshot(Iterable) may be invoked on the result.)


arraySegment

public static SizedIterable<Long> arraySegment(long[] array,
                                               int start)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through the end of the array are included. Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start is an invalid index.

arraySegment

public static SizedIterable<Long> arraySegment(long[] array,
                                               int start,
                                               int end)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through end-1 are included (and the size is thus end-start). Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start and end are inconsistent with each other or with the length of the array.

asIterable

public static SizedIterable<Float> asIterable(float[] values)
Create a SizedIterable wrapping the given array. Subsequent changes to the array will be reflected in the result. (If that is not the desired behavior, snapshot(Iterable) may be invoked on the result.)


arraySegment

public static SizedIterable<Float> arraySegment(float[] array,
                                                int start)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through the end of the array are included. Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start is an invalid index.

arraySegment

public static SizedIterable<Float> arraySegment(float[] array,
                                                int start,
                                                int end)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through end-1 are included (and the size is thus end-start). Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start and end are inconsistent with each other or with the length of the array.

asIterable

public static SizedIterable<Double> asIterable(double[] values)
Create a SizedIterable wrapping the given array. Subsequent changes to the array will be reflected in the result. (If that is not the desired behavior, snapshot(Iterable) may be invoked on the result.)


arraySegment

public static SizedIterable<Double> arraySegment(double[] array,
                                                 int start)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through the end of the array are included. Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start is an invalid index.

arraySegment

public static SizedIterable<Double> arraySegment(double[] array,
                                                 int start,
                                                 int end)
Create a SizedIterable wrapping a segment of the given array. Elements from index start through end-1 are included (and the size is thus end-start). Subsequent changes to the array will be reflected in the result; also note that entire array will remain in memory until references to this segment are discarded. (To prevent mutation and potential memory leaks, snapshot(Iterable) may be invoked on the result.)

Throws:
IndexOutOfBoundsException - If start and end are inconsistent with each other or with the length of the array.

arrayAsIterable

public static SizedIterable<?> arrayAsIterable(Object array)
Returns an iterable that traverses the given array, which may contain primitives or references.

Throws:
IllegalArgumentException - If array is not an array

asSizedIterable

public static <T> SizedIterable<T> asSizedIterable(Collection<T> coll)
Convert the given Collection to a SizedIterable. If it already is a SizedIterable, cast it as such. Otherwise, wrap it. In either case, subsequent changes made to the collection will be reflected in the result (if this is not the desired behavior, snapshot(Iterable) can be used instead).


asIterable

public static SizedIterable<Character> asIterable(CharSequence sequence)
Create an iterable that wraps the given CharSequence.


asIterable

public static SizedIterable<Character> asIterable(String sequence)
Create an iterable that wraps the given string. This is similar to asIterable(CharSequence), but takes advantage of the fact that Strings are immutable.


toIterable

public static <T> SizedIterable<T> toIterable(Option<? extends T> option)
Produce an iterable of size 0 or 1 from an Option.


toIterable

public static <T> SizedIterable<T> toIterable(Wrapper<? extends T> tuple)
Produce an iterable of size 1 from a Wrapper.


toIterable

public static <T> SizedIterable<T> toIterable(Pair<? extends T,? extends T> tuple)
Produce an iterable of size 2 from a Pair.


toIterable

public static <T> SizedIterable<T> toIterable(Triple<? extends T,? extends T,? extends T> tuple)
Produce an iterable of size 3 from a Triple.


toIterable

public static <T> SizedIterable<T> toIterable(Quad<? extends T,? extends T,? extends T,? extends T> tuple)
Produce an iterable of size 4 from a Quad.


toIterable

public static <T> SizedIterable<T> toIterable(Quint<? extends T,? extends T,? extends T,? extends T,? extends T> tuple)
Produce an iterable of size 5 from a Quint.


toIterable

public static <T> SizedIterable<T> toIterable(Sextet<? extends T,? extends T,? extends T,? extends T,? extends T,? extends T> tuple)
Produce an iterable of size 6 from a Sextet.


toIterable

public static <T> SizedIterable<T> toIterable(Septet<? extends T,? extends T,? extends T,? extends T,? extends T,? extends T,? extends T> tuple)
Produce an iterable of size 7 from a Septet.


toIterable

public static <T> SizedIterable<T> toIterable(Octet<? extends T,? extends T,? extends T,? extends T,? extends T,? extends T,? extends T,? extends T> tuple)
Produce an iterable of size 8 from an Octet.


toArray

public static <T> T[] toArray(Iterable<? extends T> iter,
                              Class<T> type)
Make an array with the given elements. Takes advantage of the (potentially optimized) Collection.toArray() method where possible; otherwise, just iterates through iter to fill the array. If the size of the iterable is larger than Integer.MAX_VALUE or is infinite, it will be truncated to fit in an array.


first

public static <T> T first(Iterable<? extends T> iter)
Access the first value in the given iterable.

Throws:
NoSuchElementException - If the iterable is empty

skipFirst

public static <T> SkipFirstIterable<T> skipFirst(Iterable<T> iter)
Produce an iterable that skips the first element of iter (if it exists)


last

public static <T> T last(Iterable<? extends T> iter)
Access the last value in the given iterable. With the exception of some special cases (OptimizedLastIterables, SortedSets, or Lists), this operation takes time on the order of the length of the list. Assumes the iterable is finite.

Throws:
NoSuchElementException - If the iterable is empty

skipLast

public static <T> SkipLastIterable<T> skipLast(Iterable<? extends T> iter)
Produce an iterable that skips the last element of iter (if it exists). Assumes the iterable is finite.


makeOption

public static <T> Option<T> makeOption(Iterable<? extends T> iter)
Convert an iterable of 0 or 1 elements to an Option.

Throws:
IllegalArgumentException - If the iterable is not of the appropriate size.

makeWrapper

public static <T> Wrapper<T> makeWrapper(Iterable<? extends T> iter)
Convert an iterable of 1 element to a Wrapper.

Throws:
IllegalArgumentException - If the iterable is not of the appropriate size.

makePair

public static <T> Pair<T,T> makePair(Iterable<? extends T> iter)
Convert an iterable of 2 elements to a Pair.

Throws:
IllegalArgumentException - If the iterable is not of the appropriate size.

makeTriple

public static <T> Triple<T,T,T> makeTriple(Iterable<? extends T> iter)
Convert an iterable of 3 elements to a Triple.

Throws:
IllegalArgumentException - If the iterable is not of the appropriate size.

makeQuad

public static <T> Quad<T,T,T,T> makeQuad(Iterable<? extends T> iter)
Convert an iterable of 4 elements to a Quad.

Throws:
IllegalArgumentException - If the iterable is not of the appropriate size.

makeQuint

public static <T> Quint<T,T,T,T,T> makeQuint(Iterable<? extends T> iter)
Convert an iterable of 5 elements to a Quint.

Throws:
IllegalArgumentException - If the iterable is not of the appropriate size.

makeSextet

public static <T> Sextet<T,T,T,T,T,T> makeSextet(Iterable<? extends T> iter)
Convert an iterable of 6 elements to a Sextet.

Throws:
IllegalArgumentException - If the iterable is not of the appropriate size.

makeSeptet

public static <T> Septet<T,T,T,T,T,T,T> makeSeptet(Iterable<? extends T> iter)
Convert an iterable of 7 elements to a Septet.

Throws:
IllegalArgumentException - If the iterable is not of the appropriate size.

makeOctet

public static <T> Octet<T,T,T,T,T,T,T,T> makeOctet(Iterable<? extends T> iter)
Convert an iterable of 8 elements to an Octet.

Throws:
IllegalArgumentException - If the iterable is not of the appropriate size.

reverse

public static <T> SizedIterable<T> reverse(Iterable<? extends T> iter)
Produce a reverse-order iterable over the given elements. Subsequent changes to iter will not be reflected in the result. Runs in linear time.


shuffle

public static <T> SizedIterable<T> shuffle(Iterable<T> iter)
Produce a shuffled iterable over the given elements. Subsequent changes to iter will not be reflected in the result. Runs in linear time.


shuffle

public static <T> SizedIterable<T> shuffle(Iterable<T> iter,
                                           Random random)
Produce a shuffled iterable over the given elements, using the specified random number generator. Subsequent changes to iter will not be reflected in the result. Runs in linear time.


sort

public static <T extends Comparable<? super T>> SizedIterable<T> sort(Iterable<T> iter)
Produce a sorted iterable over the given elements. Subsequent changes to iter will not be reflected in the result. Runs in n log n time.


sort

public static <T> SizedIterable<T> sort(Iterable<T> iter,
                                        Comparator<? super T> comp)
Produce a sorted iterable over the given elements, using the specified comparator. Subsequent changes to iter will not be reflected in the result. Runs in n log n time.


split

public static <T> Pair<SizedIterable<T>,SizedIterable<T>> split(Iterable<? extends T> iter,
                                                                int index)
Split the given iterable into two at the given index. The first index values in iter will belong to the first half; the rest will belong to the second half. Where there are less than index values in iter, the first half will contain them all and the second half will be empty. Note that the result is a snapshot — later modifications to iter will not be reflected. Assumes the iterable is finite.


truncate

public static <T> TruncatedIterable<T> truncate(Iterable<? extends T> iter,
                                                int size)
Truncate the given iterable. The result will have size less than or equal to size. Subsequent changes to iter will be reflected in the result.


collapse

public static <T> CollapsedIterable<T> collapse(Iterable<? extends Iterable<? extends T>> iters)
Collapse a list of lists into a single list. Subsequent changes to iter or its sublists will be reflected in the result.


filter

public static <T> FilteredIterable<T> filter(Iterable<? extends T> iter,
                                             Predicate<? super T> pred)
Produce an iterable that only contains values from the given iterable that satisfy a predicate.


filterSnapshot

public static <T> SnapshotIterable<T> filterSnapshot(Iterable<? extends T> iter,
                                                     Predicate<? super T> pred)
Produce an iterable that only contains values from the given iterable that satisfy a predicate.


filterInstances

public static <T> FilteredIterable<T> filterInstances(Iterable<? super T> iter,
                                                      Class<? extends T> c)
Cast all instances of the given type appropriately; filter out any non-instances.


fold

public static <T,R> R fold(Iterable<? extends T> iter,
                           R base,
                           Lambda2<? super R,? super T,? extends R> combiner)
Compute the left fold of the given list. That is, for some combination function # (written here with infix notation), compute base # iter.next() # iter.next() # .... Assumes the iterable is finite.


and

public static <T> boolean and(Iterable<? extends T> iter,
                              Predicate<? super T> pred)
Check whether the given predicate holds for all values in iter. Computation halts immediately where the predicate fails. May never halt if the iterable is infinite.


or

public static <T> boolean or(Iterable<? extends T> iter,
                             Predicate<? super T> pred)
Check whether the given predicate holds for some value in iter. Computation halts immediately where the predicate succeeds. May never halt if the interable is infinite.


and

public static <T1,T2> boolean and(Iterable<? extends T1> iter1,
                                  Iterable<? extends T2> iter2,
                                  Predicate2<? super T1,? super T2> pred)
Check whether the given predicate holds for all corresponding values in iter1 and iter2. The iterables are assumed to have the same length; computation halts immediately where the predicate fails. May never halt if the iterables are infinite.


or

public static <T1,T2> boolean or(Iterable<? extends T1> iter1,
                                 Iterable<? extends T2> iter2,
                                 Predicate2<? super T1,? super T2> pred)
Check whether the given predicate holds for some corresponding values in iter1 and iter2. The iterables are assumed to have the same length; computation halts immediately where the predicate succeeds. May never halt if the iterables are infinite.


and

public static <T1,T2,T3> boolean and(Iterable<? extends T1> iter1,
                                     Iterable<? extends T2> iter2,
                                     Iterable<? extends T3> iter3,
                                     Predicate3<? super T1,? super T2,? super T3> pred)
Check whether the given predicate holds for all corresponding values in the given iterables. The iterables are assumed to all have the same length; computation halts immediately where the predicate fails. May never halt if the iterables are infinite.


or

public static <T1,T2,T3> boolean or(Iterable<? extends T1> iter1,
                                    Iterable<? extends T2> iter2,
                                    Iterable<? extends T3> iter3,
                                    Predicate3<? super T1,? super T2,? super T3> pred)
Check whether the given predicate holds for some corresponding values in the given iterables. The iterables are assumed to all have the same length; computation halts immediately where the predicate fails. May never halt if the iterables are infinite.


and

public static <T1,T2,T3,T4> boolean and(Iterable<? extends T1> iter1,
                                        Iterable<? extends T2> iter2,
                                        Iterable<? extends T3> iter3,
                                        Iterable<? extends T4> iter4,
                                        Predicate4<? super T1,? super T2,? super T3,? super T4> pred)
Check whether the given predicate holds for all corresponding values in the given iterables. The iterables are assumed to all have the same length; computation halts immediately where the predicate fails. May never halt if the iterables are infinite.


or

public static <T1,T2,T3,T4> boolean or(Iterable<? extends T1> iter1,
                                       Iterable<? extends T2> iter2,
                                       Iterable<? extends T3> iter3,
                                       Iterable<? extends T4> iter4,
                                       Predicate4<? super T1,? super T2,? super T3,? super T4> pred)
Check whether the given predicate holds for some corresponding values in the given iterables. The iterables are assumed to all have the same length; computation halts immediately where the predicate fails. May never halt if the iterables are infinite.


map

public static <T,R> SizedIterable<R> map(Iterable<? extends T> source,
                                         Lambda<? super T,? extends R> map)
Lazily apply a map function to each element in an iterable.


mapSnapshot

public static <T,R> SnapshotIterable<R> mapSnapshot(Iterable<? extends T> source,
                                                    Lambda<? super T,? extends R> map)
Immediately apply a map function to each element in an iterable.


map

public static <T1,T2,R> SizedIterable<R> map(Iterable<? extends T1> iter1,
                                             Iterable<? extends T2> iter2,
                                             Lambda2<? super T1,? super T2,? extends R> map)
Lazily apply a map function to each corresponding pair of elements in the given iterables. The input iterables are assumed to have the same size.


mapSnapshot

public static <T1,T2,R> SnapshotIterable<R> mapSnapshot(Iterable<? extends T1> iter1,
                                                        Iterable<? extends T2> iter2,
                                                        Lambda2<? super T1,? super T2,? extends R> map)
Immediately apply a map function to each corresponding pair of elements in the given iterables. The input iterables are assumed to have the same size.


map

public static <T1,T2,T3,R> SizedIterable<R> map(Iterable<? extends T1> iter1,
                                                Iterable<? extends T2> iter2,
                                                Iterable<? extends T3> iter3,
                                                Lambda3<? super T1,? super T2,? super T3,? extends R> map)
Lazily apply a map function to each corresponding triple of elements in the given iterables. The input iterables are assumed to have the same size.


mapSnapshot

public static <T1,T2,T3,R> SnapshotIterable<R> mapSnapshot(Iterable<? extends T1> iter1,
                                                           Iterable<? extends T2> iter2,
                                                           Iterable<? extends T3> iter3,
                                                           Lambda3<? super T1,? super T2,? super T3,? extends R> map)
Immediately apply a map function to each corresponding triple of elements in the given iterables. The input iterables are assumed to have the same size.


map

public static <T1,T2,T3,T4,R> SizedIterable<R> map(Iterable<? extends T1> iter1,
                                                   Iterable<? extends T2> iter2,
                                                   Iterable<? extends T3> iter3,
                                                   Iterable<? extends T4> iter4,
                                                   Lambda4<? super T1,? super T2,? super T3,? super T4,? extends R> map)
Lazily apply a map function to each corresponding quadruple of elements in the given iterables. The input iterables are assumed to have the same size.


mapSnapshot

public static <T1,T2,T3,T4,R> SnapshotIterable<R> mapSnapshot(Iterable<? extends T1> iter1,
                                                              Iterable<? extends T2> iter2,
                                                              Iterable<? extends T3> iter3,
                                                              Iterable<? extends T4> iter4,
                                                              Lambda4<? super T1,? super T2,? super T3,? super T4,? extends R> map)
Immediately apply a map function to each corresponding quadruple of elements in the given iterables. The input iterables are assumed to have the same size.


run

public static <T> void run(Iterable<? extends T> iter,
                           Runnable1<? super T> runnable)
Apply the given runnable to every element in an iterable.


run

public static <T1,T2> void run(Iterable<? extends T1> iter1,
                               Iterable<? extends T2> iter2,
                               Runnable2<? super T1,? super T2> runnable)
Apply the given runnable to every pair of corresponding elements in the given iterables. The iterables are assumed to have the same length.


run

public static <T1,T2,T3> void run(Iterable<? extends T1> iter1,
                                  Iterable<? extends T2> iter2,
                                  Iterable<? extends T3> iter3,
                                  Runnable3<? super T1,? super T2,? super T3> runnable)
Apply the given runnable to every triple of corresponding elements in the given iterables. The iterables are assumed to have the same length.


run

public static <T1,T2,T3,T4> void run(Iterable<? extends T1> iter1,
                                     Iterable<? extends T2> iter2,
                                     Iterable<? extends T3> iter3,
                                     Iterable<? extends T4> iter4,
                                     Runnable4<? super T1,? super T2,? super T3,? super T4> runnable)
Apply the given runnable to every quadruple of corresponding elements in the given iterables. The iterables are assumed to have the same length.


cross

public static <T1,T2,R> SizedIterable<R> cross(Iterable<? extends T1> left,
                                               Iterable<? extends T2> right,
                                               Lambda2<? super T1,? super T2,? extends R> combiner)
Lazily produce the cartesian (cross) product of two iterables. Each pair of elements is combined by the given function. The order of results is defined by CartesianIterable.


cross

public static <T1,T2> SizedIterable<Pair<T1,T2>> cross(Iterable<? extends T1> left,
                                                       Iterable<? extends T2> right)
Lazily produce the cartesian (cross) product of two iterables, wrapping each combination of elements in a Pair. The order of results is defined by CartesianIterable.


diagonalCross

public static <T1,T2,R> SizedIterable<R> diagonalCross(Iterable<? extends T1> left,
                                                       Iterable<? extends T2> right,
                                                       Lambda2<? super T1,? super T2,? extends R> combiner)
Lazily produce the cartesian (cross) product of two iterables. Each pair of elements is combined by the given function. The order of results is defined by DiagonalCartesianIterable.


diagonalCross

public static <T1,T2> SizedIterable<Pair<T1,T2>> diagonalCross(Iterable<? extends T1> left,
                                                               Iterable<? extends T2> right)
Lazily produce the cartesian (cross) product of two iterables, wrapping each combination of elements in a Pair. The order of results is defined by DiagonalCartesianIterable.


cross

public static <T1,T2,T3,R> SizedIterable<R> cross(Iterable<? extends T1> iter1,
                                                  Iterable<? extends T2> iter2,
                                                  Iterable<? extends T3> iter3,
                                                  Lambda3<? super T1,? super T2,? super T3,? extends R> combiner)
Lazily produce the cartesian (cross) product of three iterables. Each triple of elements is combined by the given function. The order of results is defined by CartesianIterable.


cross

public static <T1,T2,T3> SizedIterable<Triple<T1,T2,T3>> cross(Iterable<? extends T1> iter1,
                                                               Iterable<? extends T2> iter2,
                                                               Iterable<? extends T3> iter3)
Lazily produce the cartesian (cross) product of three iterables, wrapping each combination of elements in a Triple. The order of results is defined by CartesianIterable.


diagonalCross

public static <T1,T2,T3,R> SizedIterable<R> diagonalCross(Iterable<? extends T1> iter1,
                                                          Iterable<? extends T2> iter2,
                                                          Iterable<? extends T3> iter3,
                                                          Lambda3<? super T1,? super T2,? super T3,? extends R> combiner)
Lazily produce the cartesian (cross) product of three iterables. Each triple of elements is combined by the given function. The order of results is defined by DiagonalCartesianIterable.


diagonalCross

public static <T1,T2,T3> SizedIterable<Triple<T1,T2,T3>> diagonalCross(Iterable<? extends T1> iter1,
                                                                       Iterable<? extends T2> iter2,
                                                                       Iterable<? extends T3> iter3)
Lazily produce the cartesian (cross) product of three iterables, wrapping each combination of elements in a Triple. The order of results is defined by DiagonalCartesianIterable.


cross

public static <T1,T2,T3,T4,R> SizedIterable<R> cross(Iterable<? extends T1> iter1,
                                                     Iterable<? extends T2> iter2,
                                                     Iterable<? extends T3> iter3,
                                                     Iterable<? extends T4> iter4,
                                                     Lambda4<? super T1,? super T2,? super T3,? super T4,? extends R> combiner)
Lazily produce the cartesian (cross) product of four iterables. Each quadruple of elements is combined by the given function. The order of results is defined by CartesianIterable.


cross

public static <T1,T2,T3,T4> SizedIterable<Quad<T1,T2,T3,T4>> cross(Iterable<? extends T1> iter1,
                                                                   Iterable<? extends T2> iter2,
                                                                   Iterable<? extends T3> iter3,
                                                                   Iterable<? extends T4> iter4)
Lazily produce the cartesian (cross) product of four iterables, wrapping each combination of elements in a Quad. The order of results is defined by CartesianIterable.


diagonalCross

public static <T1,T2,T3,T4,R> SizedIterable<R> diagonalCross(Iterable<? extends T1> iter1,
                                                             Iterable<? extends T2> iter2,
                                                             Iterable<? extends T3> iter3,
                                                             Iterable<? extends T4> iter4,
                                                             Lambda4<? super T1,? super T2,? super T3,? super T4,? extends R> combiner)
Lazily produce the cartesian (cross) product of four iterables. Each quadruple of elements is combined by the given function. The order of results is defined by DiagonalCartesianIterable.


diagonalCross

public static <T1,T2,T3,T4> SizedIterable<Quad<T1,T2,T3,T4>> diagonalCross(Iterable<? extends T1> iter1,
                                                                           Iterable<? extends T2> iter2,
                                                                           Iterable<? extends T3> iter3,
                                                                           Iterable<? extends T4> iter4)
Lazily produce the cartesian (cross) product of four iterables, wrapping each combination of elements in a Quad. The order of results is defined by DiagonalCartesianIterable.


cross

public static <T> SizedIterable<Iterable<T>> cross(Iterable<? extends Iterable<? extends T>> iters)
Lazily produce the cartesian (cross) product of an arbitrary number of iterables. Each tuple in the result is represented by an iterable. If iters is empty, the result is a single empty iterable. The order of results is defined by CartesianIterable. The input iterable is assumed to be finite; the elements of this list, on the other hand, need not be.


diagonalCross

public static <T> SizedIterable<Iterable<T>> diagonalCross(Iterable<? extends Iterable<? extends T>> iters)
Lazily produce the cartesian (cross) product of an arbitrary number of iterables. Each tuple in the result is represented by an iterable. If iters is empty, the result is a single empty iterable. The order of results is defined by DiagonalCartesianIterable. The input iterable is assumed to be finite; the elements of this list, on the other hand, need not be.


crossFold

public static <T,R> SizedIterable<R> crossFold(Iterable<? extends Iterable<? extends T>> iters,
                                               R base,
                                               Lambda2<? super R,? super T,? extends R> combiner)
Lazily apply the given folding function to each tuple in the cartesian (cross) product of the given iterables. The order of results is defined by CartesianIterable. The input iterable is assumed to be finite; the elements of this list, on the other hand, need not be.


diagonalCrossFold

public static <T,R> SizedIterable<R> diagonalCrossFold(Iterable<? extends Iterable<? extends T>> iters,
                                                       R base,
                                                       Lambda2<? super R,? super T,? extends R> combiner)
Lazily apply the given folding function to each tuple in the cartesian (cross) product of the given iterables. The order of results is defined by DiagonalCartesianIterable. The input iterable is assumed to be finite; the elements of this list, on the other hand, need not be.


distribute

public static <T1,A,S2> Iterable<S2> distribute(Iterable<? extends T1> original,
                                                Lambda<? super T1,? extends Iterable<? extends A>> breakT,
                                                Lambda<? super Iterable<A>,? extends S2> makeS)
Use the cross(Iterable) function to lazily apply a distribution rule to the given composite object list. Given a list of conjunctions, for example, this method transforms the list into an equivalent list of disjunctions.

Type Parameters:
T1 - The original object's components, each composed of As.
A - The type of atomic components of a T1 or S2.
S2 - The type of the result's components, again composed of As.
Parameters:
original - A list of original T1s.
breakT - Decomposes a T1 into its constituent elements.
makeS - Construct an S2 from the given elements.

distribute

public static <S1,T1,A,S2,T2> T2 distribute(S1 original,
                                            Lambda<? super S1,? extends Iterable<? extends T1>> breakS,
                                            Lambda<? super T1,? extends Iterable<? extends A>> breakT,
                                            Lambda<? super Iterable<A>,? extends S2> makeS,
                                            Lambda<? super Iterable<S2>,? extends T2> makeT)
Use the cross(Iterable) function to apply a distribution rule to the given composite object. Given constructors $ and %, for example, this method transforms an object of the form (a$b) % (c$d$e) to (a%c) $ (a%d) $ (a%e) $ (b%c) $ (b%d) $ (b%e). For maximum flexibility, the types produced by the $ and % constructors may be different from each other and from the type of atomic elements. Additionally, the type of $ applied to some %-constructed elements may be different than the type of $ applied to atomic elements (and the same for %).

Type Parameters:
S1 - The original object type, composed of T1s.
T1 - The type of S1's components, composed of As.
A - The type of atomic components of a T1 or S2.
S2 - The type of a T2's components in the result, composed of As.
T2 - The result type, composed of S2s.
Parameters:
original - The original object
breakS - Decomposes an S1 into its constituent elements.
breakT - Decomposes a T1 into its constituent elements.
makeS - Construct an S2 from the given elements.
makeT - Construct a T2 from the given elements.

valuesOf

public static <R> SizedIterable<R> valuesOf(Iterable<? extends Thunk<? extends R>> iter)
Lazily create an iterable containing the values of the given thunks.


valuesOf

public static <T,R> Iterable<R> valuesOf(Iterable<? extends Lambda<? super T,? extends R>> iter,
                                         T arg)
Lazily create an iterable containing the values of the application of the given lambdas.


valuesOf

public static <T1,T2,R> SizedIterable<R> valuesOf(Iterable<? extends Lambda2<? super T1,? super T2,? extends R>> iter,
                                                  T1 arg1,
                                                  T2 arg2)
Lazily create an iterable containing the values of the application of the given lambdas.


valuesOf

public static <T1,T2,T3,R> SizedIterable<R> valuesOf(Iterable<? extends Lambda3<? super T1,? super T2,? super T3,? extends R>> iter,
                                                     T1 arg1,
                                                     T2 arg2,
                                                     T3 arg3)
Lazily create an iterable containing the values of the application of the given lambdas.


pairFirsts

public static <T> SizedIterable<T> pairFirsts(Iterable<? extends Pair<? extends T,?>> iter)
Lazily create an iterable containing the first values of the given tuples.


pairSeconds

public static <T> SizedIterable<T> pairSeconds(Iterable<? extends Pair<?,? extends T>> iter)
Lazily create an iterable containing the second values of the given tuples.


tripleFirsts

public static <T> SizedIterable<T> tripleFirsts(Iterable<? extends Triple<? extends T,?,?>> iter)
Lazily create an iterable containing the first values of the given tuples.


tripleSeconds

public static <T> SizedIterable<T> tripleSeconds(Iterable<? extends Triple<?,? extends T,?>> iter)
Lazily create an iterable containing the second values of the given tuples.


tripleThirds

public static <T> SizedIterable<T> tripleThirds(Iterable<? extends Triple<?,?,? extends T>> iter)
Lazily create an iterable containing the third values of the given tuples.


quadFirsts

public static <T> SizedIterable<T> quadFirsts(Iterable<? extends Quad<? extends T,?,?,?>> iter)
Lazily create an iterable containing the first values of the given tuples.


quadSeconds

public static <T> SizedIterable<T> quadSeconds(Iterable<? extends Quad<?,? extends T,?,?>> iter)
Lazily create an iterable containing the second values of the given tuples.


quadThirds

public static <T> SizedIterable<T> quadThirds(Iterable<? extends Quad<?,?,? extends T,?>> iter)
Lazily create an iterable containing the third values of the given tuples.


quadFourths

public static <T> SizedIterable<T> quadFourths(Iterable<? extends Quad<?,?,?,? extends T>> iter)
Lazily create an iterable containing the fourth values of the given tuples.


zip

public static <T1,T2> SizedIterable<Pair<T1,T2>> zip(Iterable<? extends T1> iter1,
                                                     Iterable<? extends T2> iter2)
Lazily create an iterable of Pairs of corresponding values from the given iterables (assumed to always have the same length). Useful for simultaneous iteration of multiple lists in a for loop.


zip

public static <T1,T2,T3> SizedIterable<Triple<T1,T2,T3>> zip(Iterable<? extends T1> iter1,
                                                             Iterable<? extends T2> iter2,
                                                             Iterable<? extends T3> iter3)
Lazily create an iterable of Triples of corresponding values from the given iterables (assumed to always have the same length). Useful for simultaneous iteration of multiple lists in a for loop.


zip

public static <T1,T2,T3,T4> SizedIterable<Quad<T1,T2,T3,T4>> zip(Iterable<? extends T1> iter1,
                                                                 Iterable<? extends T2> iter2,
                                                                 Iterable<? extends T3> iter3,
                                                                 Iterable<? extends T4> iter4)
Lazily create an iterable of Quads of corresponding values from the given iterables (assumed to always have the same length). Useful for simultaneous iteration of multiple lists in a for loop.