|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.cm.frw.core.fun.impl.Function de.cm.frw.core.fun.impl.PF
public class PF
PF is a name space for static components in support of pure functional programming. These operate mainly on functions to create new functions.
The concepts are implemented as static member Function instances.
Example O: Composition
The static method PF.compose
takes two function instance
f
and g
and returs a new function
c = f.g with c(args) = f(g(args))The composition is implemented as a function instance of two arguments (functions f and g) that produces a new function (c)
Example I: Reduction
While it is possible to use Function.reduce
to perform a reduction by reducing an
Iterable through repeated application of a given function, the PF.reduce
method
takes a function and an initial value to produce a new function, that can be applied
to an Iterable.
To achieve this the PF.reduce method
uses the Function instance reduce
,
i.e. the reduction is implemented as a function and can itself be used in higher
order concepts.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class de.cm.frw.core.fun.impl.Function |
---|
Function.InvalidArguments |
Field Summary | |
---|---|
static Function |
adapt
adapt is a function of three arguments
f : a function of n arguments
i : an integer with 0 <= i < n
g : a function of one argument
that produces a new function a of n arguments that computes its result
by applying f to its arguments using g(x) in parameter position i: |
static Function |
bind
bind is a function of three arguments
f : a function of n arguments
i : an integer with 0 <= i < n
x : an Object
that produces a new function b of n - 1 arguments that computes its result
by applying f to its n - 1 arguments using x in parameter position i: |
static Function |
compose
compose is a function of two arguments
f : a function of one argument
g : a function of n arguments
that produces an new function c of n arguments (i.e. |
static Function |
map
|
static Function |
reduce
reduce is a function of two arguments
f : a function of two arguments,
init : an object
that produces a new Function R of one arguments
I : an Iterable instance { i_1, ..., i_n }
as follows: |
static Function |
unary
unary is a function of one argument
f : a function of n parameters
that produces a new function U of one argument
x : an object
that puts its single argument x in all parameter positions of f, hence |
Constructor Summary | |
---|---|
PF(Function f)
|
Method Summary | |
---|---|
static Function |
adapt(Function f,
int i,
Function a)
|
PF |
adapt(int pos,
Function a)
|
java.lang.Object |
apply()
|
java.lang.Object |
apply(java.util.Collection args)
Applies the implemented function to the passed in collection of arguments. |
java.lang.Object |
apply(java.lang.Object arg)
|
int |
arity()
|
static Function |
bind(Function f,
int i,
java.lang.Object arg)
|
PF |
bind(int pos,
java.lang.Object val)
|
void |
checkArguments(java.util.Collection args)
Override this method to check conditions on the arguments (like types) passed to the function in apply before the operate method is called. |
PF |
compose(Function g)
|
static Function |
compose(Function f,
Function g)
|
java.lang.Iterable |
map(java.util.Collection args)
|
static Function |
map(Function f)
|
java.lang.Object |
operate(java.lang.Object[] operands)
Override this to implement the actual operation realized by this function. |
static Function |
reduce(Function f,
java.lang.Object init)
|
PF |
unary()
|
static Function |
unary(Function f)
|
Methods inherited from class de.cm.frw.core.fun.impl.Function |
---|
apply, apply, apply, apply, apply, apply, apply, apply, apply, apply, apply, apply, apply, apply, apply, box, box, box, box, box, box, box, box, box, box, box, box, box, box, box, is, main, map, reduce, unbox, val |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Function compose
compose
is a function of two arguments
compose
(f, g) = c with c(x1, ... , xn) = f(g(x1, ... , xn))
Note: this is sometimes written as c = f . g
public static final Function bind
bind
is a function of three arguments
bind
(f, i, x) = b with b(x1, ... , xn-1) = f(x1, .., xi-1, x , xi+1, .. , xn-1)
Note: parameter positions are counted from 0
public static final Function adapt
adapt
is a function of three arguments
adapt
(f, i, g) = a with a(x1, ... , xn) = f(x1, .., g(xi), .. , xn)
Note: parameter positions are counted from 0
public static final Function unary
unary
is a function of one argument
unary
(f) = U with
U(x) = f(x, x, ... , x)
public static final Function reduce
reduce
is a function of two arguments
Iterable
instance { i_1, ..., i_n }
reduce
(f, init) = R with
R(I) = R(i_1 ... i_n) = f(i_n, f(i_n-1, ... , f(i_1, init)))
public static final Function map
Constructor Detail |
---|
public PF(Function f)
Method Detail |
---|
public static Function compose(Function f, Function g)
public static Function bind(Function f, int i, java.lang.Object arg)
public static Function adapt(Function f, int i, Function a) throws Function.InvalidArguments
Function.InvalidArguments
public static Function unary(Function f) throws Function.InvalidArguments
Function.InvalidArguments
public static Function reduce(Function f, java.lang.Object init) throws Function.InvalidArguments
Function.InvalidArguments
public static Function map(Function f) throws Function.InvalidArguments
Function.InvalidArguments
public PF bind(int pos, java.lang.Object val) throws Function.InvalidArguments
Function.InvalidArguments
public PF adapt(int pos, Function a) throws Function.InvalidArguments
Function.InvalidArguments
public PF compose(Function g) throws Function.InvalidArguments
Function.InvalidArguments
public PF unary() throws Function.InvalidArguments
Function.InvalidArguments
public java.lang.Object apply(java.util.Collection args) throws Function.InvalidArguments
Function
apply
in class Function
args
- A collection of arguments
Function.InvalidArguments
public void checkArguments(java.util.Collection args) throws Function.InvalidArguments
Function
checkArguments
in class Function
Function.InvalidArguments
public java.lang.Object operate(java.lang.Object[] operands) throws Function.InvalidArguments
Function
Remember to document the number and types of the operands
and any other conditions for running the operate method.
Or implement checkArguments
instead.
Default implementation returns first argument passed in, realizing sort of an unary identity function.
operate
in class Function
operands
- An array of the arguments that where passed to apply
Function.InvalidArguments
- when you implement it to do so ...public java.lang.Object apply() throws Function.InvalidArguments
apply
in class Function
Function.InvalidArguments
public java.lang.Object apply(java.lang.Object arg) throws Function.InvalidArguments
apply
in class Function
Function.InvalidArguments
public java.lang.Iterable map(java.util.Collection args) throws Function.InvalidArguments
map
in class Function
Function.InvalidArguments
public int arity()
arity
in class Function
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |