com.twitter.common.collections
Class Iterables2

java.lang.Object
  extended by com.twitter.common.collections.Iterables2

public final class Iterables2
extends Object

Utility functions for dealing with iterables.


Method Summary
static
<T> Iterable<List<T>>
zip(Iterable<Iterable<T>> iterables, T defaultValue)
          Zips multiple iterables into one iterable that will return iterators to step over rows of the input iterators (columns).
static
<T> Iterable<List<T>>
zip(T defaultValue, Iterable<T>... iterables)
          Varargs convenience function to call zip(Iterable, Object).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

zip

public static <T> Iterable<List<T>> zip(Iterable<Iterable<T>> iterables,
                                        T defaultValue)
Zips multiple iterables into one iterable that will return iterators to step over rows of the input iterators (columns). The order of the returned values within each row will match the ordering of the input iterables. The iterators will iterate the length of the longest input iterable, filling other columns with defaultValue. The returned iterator is lazy, in that 'rows' are constructed as they are requested.

Type Parameters:
T - Type of value being iterated over.
Parameters:
iterables - Columns to iterate over.
defaultValue - Default fill value when an input iterable is exhausted.
Returns:
An iterator that iterates over rows of the input iterables.

zip

public static <T> Iterable<List<T>> zip(T defaultValue,
                                        Iterable<T>... iterables)
Varargs convenience function to call zip(Iterable, Object).

Type Parameters:
T - Type of value being iterated over.
Parameters:
defaultValue - Default fill value when an input iterable is exhausted.
iterables - Columns to iterate over.
Returns:
An iterator that iterates over rows of the input iterables.