|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.myjavatools.lib.foundation.Function2<X,Y,Z>
public abstract class Function2<X,Y,Z>
Function2 is an abstract class that represents the mathematical notion of two-parameter function: X x Y -> Z. To implement a function, you need to define method apply(): Z z = function.apply(X x, Y y).
Filter
,
Maps
,
Function
Constructor Summary | |
---|---|
Function2()
|
Method Summary | ||
---|---|---|
abstract Z |
apply(X x,
Y y)
the only method you should implement |
|
static
|
compose(Function<A,? extends X> f,
Function<B,? extends Y> g,
Function2<? super X,? super Y,? extends Z> h)
Returns a compostion (f,g).h : AxB->Z of a two-parameter function, h: XxY->Z and two single-parameter functions, f:A->Z and g:B->Y. |
|
static
|
compose(Function2<X,Y,? extends Z> f,
Function<? super Z,? extends T> g)
Returns a compostion f.g : XxY->T of a two-parameter function, f: XxY->Z and g: Z->T. |
|
Function<Y,Z> |
curry1(X x)
Curries the function by the first argument. |
|
Function<X,Z> |
curry2(Y y)
Curries the function by the second argument. |
|
static
|
forFunction(Function<java.util.Map.Entry<X,Y>,Z> f)
Creates a two-parameter function for a function defined on pairs. |
|
static
|
forMap(java.util.Map<X,java.util.Map<Y,Z>> map)
Creates a two-parameter function for a "cascade map". |
|
static
|
forMap(java.util.Map<X,java.util.Map<Y,Z>> map,
Z defaultValue)
Creates a two-parameter function for a "cascade map". |
|
static
|
p1()
First component projection. |
|
static
|
p2()
Second component projection. |
|
Function2<Y,X,Z> |
swap()
Swaps function arguments. |
|
Function<java.util.Map.Entry<X,Y>,Z> |
toFunction()
Converts a two-parameter function to a function on pairs, (X x, Y y). |
|
java.util.Map<X,java.util.Map<Y,Z>> |
toMap(java.util.Set<? extends X> xKeys,
java.util.Set<? extends Y> yKeys)
Creates a (virtual) map for a two-parameter function. |
|
Z |
zz(X x)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Function2()
Method Detail |
---|
public abstract Z apply(X x, Y y)
x
- X the function parametery
- Y the function parameter
public static <X,Y> Function2<X,Y,X> p1()
public static <X,Y> Function2<X,Y,Y> p2()
public Function<java.util.Map.Entry<X,Y>,Z> toFunction()
public static <X,Y,Z> Function2<X,Y,Z> forFunction(Function<java.util.Map.Entry<X,Y>,Z> f)
f
- Function that takes Map.Entry as an argument and returns
an instance of Z
public static <X,Y,Z> Function2<X,Y,Z> forMap(java.util.Map<X,java.util.Map<Y,Z>> map, Z defaultValue)
map
- <X,Map<Y,Z>>MapdefaultValue
- Z default function value for parameters that are not
contained as keys in Map
X x Y
and taking values in
Z
. For a map m
, an X x
, and
a Y y
, the value of the function is calculated like this:
m.get(x).get(y)
. If any of these get() returns null
,
the function returns defaultValue
.public static <X,Y,Z> Function2<X,Y,Z> forMap(java.util.Map<X,java.util.Map<Y,Z>> map)
map
- <X,Map<Y,Z>>Map
X x Y
and taking values in
Z
. For a map m
, an X x
, and
a Y y
, the value of the function is calculated like this:
m.get(x).get(y)
. If any of these get() returns null
,
the function returns null
.public java.util.Map<X,java.util.Map<Y,Z>> toMap(java.util.Set<? extends X> xKeys, java.util.Set<? extends Y> yKeys)
xKeys
- Set the set of keys for the first argumentyKeys
- Set the set of keys for the second argument
public Function2<Y,X,Z> swap()
public Function<Y,Z> curry1(X x)
x
- X
Y y
returns f(x,y)
.public Z zz(X x)
public Function<X,Z> curry2(Y y)
y
- Y
X x
returns f(x,y)
.public static <X,Y,Z,T> Function2<X,Y,T> compose(Function2<X,Y,? extends Z> f, Function<? super Z,? extends T> g)
f
- Function2<X,Y,Z>g
- Function<Z,T>
public static <A,B,X,Y,Z> Function2<A,B,Z> compose(Function<A,? extends X> f, Function<B,? extends Y> g, Function2<? super X,? super Y,? extends Z> h)
f
- Function<A,X>g
- Function<B,Y>h
- Function2<X,Y,Z>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |