Class ImmutableCompoundIterable<A,B>

  extended by jpaul.DataStructs.ImmutableCompoundIterable<A,B>
All Implemented Interfaces:

public class ImmutableCompoundIterable<A,B>
extends java.lang.Object
implements java.lang.Iterable<B>

ImmutableCompoundIterable allows the construction of an IMMUTABLE Iterable by merging several smaller Iterables. Given an iterable with elements a0, a1, ..., ak, and a function f that transforms each ai into an iterable, the ImmutableCompoundIterable will contain all elements from f(a0), followed by all the elements from f(a1) and so on.

The elements of a ImmutableCompoundIterable are generated lazily, as we iterate over them. This technique is better than eager iteration in the case when (1) f is simple; (2) the original Iterable changes dynamically; (3) the number of traversals is small; or (3) the number of elements is very large.

Note on immutability: While it is possible to implement a mutable CompoundIterable (i.e., the user is able to remove elements), that would be very hard to specify: e.g., what if the function always returns a brand-new Iterable that ignores the past removals?

$Id:,v 1.3 2006/03/14 02:29:31 salcianu Exp $
Alexandru Salcianu -

Constructor Summary
ImmutableCompoundIterable(java.lang.Iterable<A> collA, Function<A,java.lang.Iterable<B>> a2iter)
          Creates an ImmutableCompoundIterable.
Method Summary
 java.util.Iterator<B> iterator()
 java.lang.String toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public ImmutableCompoundIterable(java.lang.Iterable<A> collA,
                                 Function<A,java.lang.Iterable<B>> a2iter)
Creates an ImmutableCompoundIterable.

collA - An iterable of elements of type A.
a2iter - A function that transforms each element from collA into an Iterable of Bs.
Method Detail


public java.util.Iterator<B> iterator()
Specified by:
iterator in interface java.lang.Iterable<B>


public java.lang.String toString()
toString in class java.lang.Object

Copyright 2005 Alexandru Salcianu -