org.qi4j.functional
Class ForEach<T>

java.lang.Object
  extended by org.qi4j.functional.ForEach<T>
All Implemented Interfaces:
java.lang.Iterable<T>

public final class ForEach<T>
extends java.lang.Object
implements java.lang.Iterable<T>

When using Iterables with map() and filter() the code often reads "in reverse", with the first item last in the code. Example: Iterables.map(function,Iterables.filter(specification, iterable))

This ForEach class reverses that order and makes the code more readable, and allows easy application of visitors on iterables. Example: forEach(iterable).filter(specification).map(function).visit(visitor)


Constructor Summary
ForEach(java.lang.Iterable<T> iterable)
           
 
Method Summary
 ForEach<T> filter(Specification<? super T> specification)
           
<TO> ForEach<TO>
flatten()
           
static
<T> ForEach<T>
forEach(java.lang.Iterable<T> iterable)
           
 java.util.Iterator<T> iterator()
           
 T last()
           
<TO> ForEach<TO>
map(Function<?,TO> function)
           
<ThrowableType extends java.lang.Throwable>
boolean
visit(Visitor<T,ThrowableType> visitor)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ForEach

public ForEach(java.lang.Iterable<T> iterable)
Method Detail

forEach

public static <T> ForEach<T> forEach(java.lang.Iterable<T> iterable)

iterator

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

filter

public ForEach<T> filter(Specification<? super T> specification)

map

public <TO> ForEach<TO> map(Function<?,TO> function)

flatten

public <TO> ForEach<TO> flatten()

last

public T last()

visit

public <ThrowableType extends java.lang.Throwable> boolean visit(Visitor<T,ThrowableType> visitor)
              throws ThrowableType extends java.lang.Throwable
Throws:
ThrowableType extends java.lang.Throwable