net.sf.jga.fn.algorithm

Class ForEach<T,R>

public class ForEach<T,R> extends AbstractUnaryFunctor<Iterator<? extends T>,R> implements Serializable

Applies a UnaryFunctor to each element in an iteration, and returns the final result. Each element in the iteration is passed to the functor in turn. The result of the final call to the functor is returned. If the iteration was empty, then the result of this function is null.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceForEach.Visitor
Interface for classes that may interpret an ForEach functor.
Constructor Summary
ForEach(UnaryFunctor<T,R> fn)
Builds a ForEach functor that will use the given functor to process elements in an iteration.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(ForEach) method, if it implements the nested Visitor interface.
Rfn(Iterator<? extends T> iterator)
Apply the functor to each element in the iteration and return the final result.
UnaryFunctor<T,R>getFunction()
Returns the functor used to process elements in an iteration.
StringtoString()

Constructor Detail

ForEach

public ForEach(UnaryFunctor<T,R> fn)
Builds a ForEach functor that will use the given functor to process elements in an iteration.

Throws: IllegalArgumentException if the functor is null

Method Detail

accept

public void accept(Visitor v)
Calls the Visitor's visit(ForEach) method, if it implements the nested Visitor interface.

fn

public R fn(Iterator<? extends T> iterator)
Apply the functor to each element in the iteration and return the final result.

UNKNOWN: the result of the last execution of the functor, or null if the functor is not executed.

getFunction

public UnaryFunctor<T,R> getFunction()
Returns the functor used to process elements in an iteration.

toString

public String toString()