org.qi4j.functional
Class ForEach<T>
java.lang.Object
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)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ForEach
public ForEach(java.lang.Iterable<T> iterable)
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