jpaul.DataStructs
Class ImmutableCompoundIterable<A,B>
java.lang.Object
jpaul.DataStructs.ImmutableCompoundIterable<A,B>
- All Implemented Interfaces:
- java.lang.Iterable<B>
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
Iterable
s. Given an iterable with elements
a0
, a1
, ..., ak
, and a
function f
that transforms each a
i 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?
- Version:
- $Id: ImmutableCompoundIterable.java,v 1.3 2006/03/14 02:29:31 salcianu Exp $
- Author:
- Alexandru Salcianu - salcianu@alum.mit.edu
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
ImmutableCompoundIterable
public ImmutableCompoundIterable(java.lang.Iterable<A> collA,
Function<A,java.lang.Iterable<B>> a2iter)
- Creates an
ImmutableCompoundIterable
.
- Parameters:
collA
- An iterable of elements of type A
.a2iter
- A function that transforms each element from
collA
into an Iterable
of
B
s.
iterator
public java.util.Iterator<B> iterator()
- Specified by:
iterator
in interface java.lang.Iterable<B>
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
Copyright 2005 Alexandru Salcianu - salcianu@alum.mit.edu