net.sf.jga.fn.adaptor
Class ComposeBinary<T1,T2,F1,F2,R>

java.lang.Object
  extended by net.sf.jga.fn.Functor<R>
      extended by net.sf.jga.fn.BinaryFunctor<T1,T2,R>
          extended by net.sf.jga.fn.adaptor.ComposeBinary<T1,T2,F1,F2,R>
All Implemented Interfaces:
java.io.Serializable, Visitable

public class ComposeBinary<T1,T2,F1,F2,R>
extends BinaryFunctor<T1,T2,R>

Binary Functor that passes the results of two inner Binary Functors as the arguments to an outer Binary Functor. This allows for the construction of compound functors from the primitives found in the arithmetic, logical, property, and comparison packages.

Copyright © 2002-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface ComposeBinary.Visitor
          Interface for classes that may interpret a ComposeBinary functor.
 
Constructor Summary
ComposeBinary(BinaryFunctor<T1,T2,F1> f, BinaryFunctor<T1,T2,F2> g, BinaryFunctor<F1,F2,R> h)
          Builds a ComposeBinary functor, given two inner functors f and g, and outer functor h.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(ComposeBinary) method, if it implements the nested Visitor interface.
 R fn(T1 x, T2 y)
          Given argument x, passes x to both inner functors, and passes the results of those functors to the outer functor.
 BinaryFunctor<T1,T2,F1> getFirstInnerFunctor()
          Returns the first of two inner functors
 BinaryFunctor<F1,F2,R> getOuterFunctor()
          Returns the outer functor
 BinaryFunctor<T1,T2,F2> getSecondInnerFunctor()
          Returns the second of two inner functors
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.BinaryFunctor
bind, bind0th, bind1st, bind2nd, bindNth, compose, compose, composeNth, distribute, eval, generate, generate1st, generate2nd, generateNth
 
Methods inherited from class net.sf.jga.fn.Functor
composeNth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ComposeBinary

public ComposeBinary(BinaryFunctor<T1,T2,F1> f,
                     BinaryFunctor<T1,T2,F2> g,
                     BinaryFunctor<F1,F2,R> h)
Builds a ComposeBinary functor, given two inner functors f and g, and outer functor h.

Throws:
java.lang.IllegalArgumentException - if any of the functors is missing
Method Detail

getFirstInnerFunctor

public BinaryFunctor<T1,T2,F1> getFirstInnerFunctor()
Returns the first of two inner functors

Returns:
the first of two inner functors

getSecondInnerFunctor

public BinaryFunctor<T1,T2,F2> getSecondInnerFunctor()
Returns the second of two inner functors

Returns:
the second of two inner functors

getOuterFunctor

public BinaryFunctor<F1,F2,R> getOuterFunctor()
Returns the outer functor

Returns:
the outer functor

fn

public R fn(T1 x,
            T2 y)
Given argument x, passes x to both inner functors, and passes the results of those functors to the outer functor.

Specified by:
fn in class BinaryFunctor<T1,T2,R>
Returns:
h(f(x,y), g(x,y))

accept

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

Specified by:
accept in interface Visitable
Overrides:
accept in class Functor<R>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2002-2006 David A. Hall. All Rights Reserved.