net.sf.jga.fn.adaptor

Class ChainBinary<T1,T2,F,R>

public class ChainBinary<T1,T2,F,R> extends AbstractBinaryFunctor<T1,T2,R> implements Serializable

Binary Functor that passes the results of a Binary Functor as the argument to a Unary Functor. This allows for the construction of compound functors from the primitives found in the arithmetic, logical, property, and comparison packages.

Copyright © 2002 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceChainBinary.Visitor
Interface for classes that may interpret a ChainBinary functor.
Constructor Summary
ChainBinary(UnaryFunctor<F,R> f, BinaryFunctor<T1,T2,F> g)
Builds a ChainBinary functor, given inner functors f and outer functor g.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(ChainBinary) method, if it implements the nested Visitor interface.
Rfn(T1 x, T2 y)
Passes arguments x and y to the inner functor, and passes the result to the outer functor.
BinaryFunctor<T1,T2,F>getOuter()
Returns the inner functor
UnaryFunctor<F,R>getOuterFn()
Returns the outer functor
StringtoString()

Constructor Detail

ChainBinary

public ChainBinary(UnaryFunctor<F,R> f, BinaryFunctor<T1,T2,F> g)
Builds a ChainBinary functor, given inner functors f and outer functor g.

Throws: IllegalArgumentException if any of the functors is missing

Method Detail

accept

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

fn

public R fn(T1 x, T2 y)
Passes arguments x and y to the inner functor, and passes the result to the outer functor.

Returns: f(g(x,y))

getOuter

public BinaryFunctor<T1,T2,F> getOuter()
Returns the inner functor

Returns: the inner functor

getOuterFn

public UnaryFunctor<F,R> getOuterFn()
Returns the outer functor

Returns: the outer functor

toString

public String toString()