info.javelot.functionalj
Interface Function1<R,P>

Type Parameters:
R - the type of the result returned by the function.
P - the type of the function's parameter.
All Known Implementing Classes:
Function1Impl

public interface Function1<R,P>

Interface that represents a function of 1 parameter.

About function composition

Function composition consists of composing a function f and a function g to obtain a new function h, such that h(x) = f(g(x)). Since the result of calling g becomes the parameter to the function f, f must be a function of 1 parameter. This is why the compose methods are defined only in the interface of a function of 1 parameter.

On the other hand, the function g can be a function of any number of parameters, but its return type must be compatible with the parameter type of the function f. The resulting function h will be a function of the same number of parameters as the function g, but with the return type of f. Calling h with parameters will first call g with those parameters, use the result as a parameter to calling the function f, and return that result.

Author:
Copyright © 2006 Frederic Daoud

Method Summary
 Function0<R> bind(P p_param)
          Binds the parameter of this function of 1 parameter to return a new function of no parameters.
 R call(P p_param)
          Calls the function on the given parameter and returns the result.
 Function0<R> compose(Function0<P> p_function0)
          Composes this function with the given function to return a new function according to function composition as described in the interface Function1.
<P1> Function1<R,P1>
compose(Function1<P,P1> p_function1)
          Composes this function with the given function to return a new function according to function composition as described in the interface Function1.
<P1,P2> Function2<R,P1,P2>
compose(Function2<P,P1,P2> p_function2)
          Composes this function with the given function to return a new function according to function composition as described in the interface Function1.
<P1,P2,P3> Function3<R,P1,P2,P3>
compose(Function3<P,P1,P2,P3> p_function3)
          Composes this function with the given function to return a new function according to function composition as described in the interface Function1.
<P1,P2,P3,P4>
Function4<R,P1,P2,P3,P4>
compose(Function4<P,P1,P2,P3,P4> p_function4)
          Composes this function with the given function to return a new function according to function composition as described in the interface Function1.
 FunctionN<R> compose(FunctionN<P> p_functionN)
          Composes this function with the given function to return a new function according to function composition as described in the interface Function1.
 

Method Detail

call

R call(P p_param)
       throws FunctionException
Calls the function on the given parameter and returns the result.

Parameters:
p_param - the parameter to the function.
Returns:
the result of the function call.
Throws:
FunctionException - thrown if an exception occurs during the function call.

bind

Function0<R> bind(P p_param)
Binds the parameter of this function of 1 parameter to return a new function of no parameters.

Parameters:
p_param - the parameter to bind to the function.
Returns:
a new function of no parameters.

compose

Function0<R> compose(Function0<P> p_function0)
Composes this function with the given function to return a new function according to function composition as described in the interface Function1.

Parameters:
p_function0 - the function g to compose with this function f.
Returns:
a new function h such that h(x) = f(g(x)), where x represents all parameters accepted by g.

compose

<P1> Function1<R,P1> compose(Function1<P,P1> p_function1)
Composes this function with the given function to return a new function according to function composition as described in the interface Function1.

Parameters:
p_function1 - the function g to compose with this function f.
Returns:
a new function h such that h(x) = f(g(x)), where x represents all parameters accepted by g.

compose

<P1,P2> Function2<R,P1,P2> compose(Function2<P,P1,P2> p_function2)
Composes this function with the given function to return a new function according to function composition as described in the interface Function1.

Parameters:
p_function2 - the function g to compose with this function f.
Returns:
a new function h such that h(x) = f(g(x)), where x represents all parameters accepted by g.

compose

<P1,P2,P3> Function3<R,P1,P2,P3> compose(Function3<P,P1,P2,P3> p_function3)
Composes this function with the given function to return a new function according to function composition as described in the interface Function1.

Parameters:
p_function3 - the function g to compose with this function f.
Returns:
a new function h such that h(x) = f(g(x)), where x represents all parameters accepted by g.

compose

<P1,P2,P3,P4> Function4<R,P1,P2,P3,P4> compose(Function4<P,P1,P2,P3,P4> p_function4)
Composes this function with the given function to return a new function according to function composition as described in the interface Function1.

Parameters:
p_function4 - the function g to compose with this function f.
Returns:
a new function h such that h(x) = f(g(x)), where x represents all parameters accepted by g.

compose

FunctionN<R> compose(FunctionN<P> p_functionN)
Composes this function with the given function to return a new function according to function composition as described in the interface Function1.

Parameters:
p_functionN - the function g to compose with this function f.
Returns:
a new function h such that h(x) = f(g(x)), where x represents all parameters accepted by g.