|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.jga.fn.Functor<R> net.sf.jga.fn.UnaryFunctor<T,R> net.sf.jga.fn.adaptor.ComposeUnary<T,F1,F2,R>
public class ComposeUnary<T,F1,F2,R>
Unary Functor that passes the results of two Unary Functors as the arguments to a Binary Functor. This allows for the construction of compound functors from the primitives found in the arithmetic, logical, property, and comparison packages.
For example: LogicalAnd is of limited utility since it takes only Boolean arguments. To use LogicalAnd for something a little more interesting (eg, is the given integer between 1 and 10), combine LogicalAnd with GreaterEqual and LessEqual using Binary Compose and Bind1st as follows:
new ComposeUnary<Integer,Boolean,Boolean,Boolean> ( new Bind1st<Integer,Integer,Boolean> (1, new LessEqual<Integer>()), new Bind1st<Integer,Integer,Boolean> (10, new GreaterEqual<Integer>()), new LogicalAnd());While it may not be the most readable construction in the world, it does become easier over time.
Copyright © 2002-2005 David A. Hall
Nested Class Summary | |
---|---|
static interface |
ComposeUnary.Visitor
Interface for classes that may interpret a ComposeUnary functor. |
Constructor Summary | |
---|---|
ComposeUnary(UnaryFunctor<T,F1> f,
UnaryFunctor<T,F2> g,
BinaryFunctor<F1,F2,R> h)
Builds a ComposeUnary functor, given two inner functors f and g, and outer functor h. |
Method Summary | |
---|---|
void |
accept(Visitor v)
Calls the Visitor's visit(ComposeUnary) method, if it
implements the nested Visitor interface. |
R |
fn(T x)
Given argument x, passes x to both inner functors, and passes the results of those functors to the outer functor. |
UnaryFunctor<T,F1> |
getFirstInnerFunctor()
Returns the first of two inner functors |
BinaryFunctor<F1,F2,R> |
getOuterFunctor()
Returns the outer functor |
UnaryFunctor<T,F2> |
getSecondInnerFunctor()
Returns the second of two inner functors |
java.lang.String |
toString()
|
Methods inherited from class net.sf.jga.fn.UnaryFunctor |
---|
bind, bind0th, bindNth, compose, compose, compose, composeNth, composeNth, eval, generate, generateNth |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ComposeUnary(UnaryFunctor<T,F1> f, UnaryFunctor<T,F2> g, BinaryFunctor<F1,F2,R> h)
java.lang.IllegalArgumentException
- if any of the functors is missingMethod Detail |
---|
public UnaryFunctor<T,F1> getFirstInnerFunctor()
public UnaryFunctor<T,F2> getSecondInnerFunctor()
public BinaryFunctor<F1,F2,R> getOuterFunctor()
public R fn(T x)
fn
in class UnaryFunctor<T,R>
public void accept(Visitor v)
visit(ComposeUnary)
method, if it
implements the nested Visitor interface.
accept
in interface Visitable
accept
in class Functor<R>
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |