net.sf.jga.fn
Class Functor<R>

java.lang.Object
  extended by net.sf.jga.fn.Functor<R>
All Implemented Interfaces:
java.io.Serializable, Visitable
Direct Known Subclasses:
BinaryFunctor, BindNth, ChainFunctor, ComposeBinaryNth, ComposeUnaryNth, Compound, GenerateNth, Generator, Invoke, Multiplex, UnaryFunctor

public abstract class Functor<R>
extends java.lang.Object
implements java.io.Serializable, Visitable

A Function object that accepts an arbitrary number of arguments and returns a value of type R. The Functor interface is generally not typesafe. It is typesafe with respect to the return type (R), but the compiler cannot ensure that the number of arguments or their types are appropriate for any given implementation of the Functor interface. However, three direct subclasses, Generator, UnaryFunctor, and BindaryFunctor are typesafe, provided their interfaces are used in leiu of this interface.

In short, if you want the compiler to enforce type safetype with respect to the number and type of arguments, then do not use the method(s) defined by this class: use the methods defined by the typesafe derived classes.

Copyright © 2006 David A. Hall

See Also:
Serialized Form

Constructor Summary
Functor()
           
 
Method Summary
 void accept(Visitor v)
          default implementation of Visitable interface.
 Functor<R> bind0th(java.lang.Object arg0, java.lang.Object... args)
          Binds the given values to this functor, starting from the first argument.
 Functor<R> bindNth(int idx, java.lang.Object arg0, java.lang.Object... args)
          Binds the given values to this functor, starting from the given index.
 Functor<R> composeNth(int idx, BinaryFunctor<?,?,?> bf)
          Uses the given functor to replace two arguments at the given index with a single value
 Functor<R> composeNth(int idx, UnaryFunctor<?,?> uf)
          Uses the given functor to replace an argument at the given index
abstract  R eval(java.lang.Object... args)
          A non-typesafe evaluation method for function objects.
 Functor<R> generateNth(int idx, Generator<?> gen)
          Uses the given generator to insert an argument at the given index
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Functor

public Functor()
Method Detail

eval

public abstract R eval(java.lang.Object... args)
A non-typesafe evaluation method for function objects. The number and types of arguments is not checked at compile time: an invalid number of arguments may cause IndexOutOfBoundsException (or cause extraneous arguments to be ignored); an argument of an invalid type may cause a ClassCastException.


bind0th

public Functor<R> bind0th(java.lang.Object arg0,
                          java.lang.Object... args)
Binds the given values to this functor, starting from the first argument.

Parameters:
arg0 -
args -
Returns:

bindNth

public Functor<R> bindNth(int idx,
                          java.lang.Object arg0,
                          java.lang.Object... args)
Binds the given values to this functor, starting from the given index.

Parameters:
idx -
arg0 -
args -
Returns:

generateNth

public Functor<R> generateNth(int idx,
                              Generator<?> gen)
Uses the given generator to insert an argument at the given index

Parameters:
idx -
arg0 -
args -
Returns:

composeNth

public Functor<R> composeNth(int idx,
                             UnaryFunctor<?,?> uf)
Uses the given functor to replace an argument at the given index

Parameters:
idx -
arg0 -
args -
Returns:

composeNth

public Functor<R> composeNth(int idx,
                             BinaryFunctor<?,?,?> bf)
Uses the given functor to replace two arguments at the given index with a single value

Parameters:
idx -
arg0 -
args -
Returns:

accept

public void accept(Visitor v)
default implementation of Visitable interface.

Specified by:
accept in interface Visitable


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