|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjfun.yan.Monad
public class Monad
The facade class to provide monadic combinators for Component.
map(jfun.yan.Creator, jfun.yan.Map) only maps one Creator,
this class provides additional map combinator to map 2, 3, 4, 5 Creators to a Component.
For mapping for more than 5 Creator objects,
use Component.map(jfun.yan.Map) together with
Components.array(jfun.yan.Component[])
or Components.list(jfun.yan.Creator[])
or Components.list(java.util.List).
The bind() combinator is the ultimate resort to get flexibility.
Codehaus.org.
| Constructor Summary | |
|---|---|
Monad()
|
|
| Method Summary | ||
|---|---|---|
static
|
bind(Creator<From> c1,
Binder<From,To> binder)
Monadic 'bind' operation. |
|
static
|
bind(Creator<From> c1,
ComponentBinder<From,To> binder)
Monadic 'bind' operation. |
|
static Component |
fail(java.lang.String msg)
Create a Component that always fails. |
|
static
|
followedBy(Component<T> c1,
Binder<T,?> binder)
Create a staged component. |
|
static
|
followedBy(Component<T> c1,
ComponentBinder<T,?> binder)
Create a staged component. |
|
static
|
followedBy(Component<T> c1,
Creator<?> c2)
Create a staged component. |
|
static
|
ifelse(Creator<java.lang.Boolean> cond,
Component<T> a,
Component<T> b)
Create a Component object according to the boolean value returned from another Component. |
|
static ComponentBinder |
instantiator()
To create a ComponentBinder object that instantiates the Creator object created from the previous step. |
|
static
|
map(Creator<A> c1,
Creator<B> c2,
Creator<C> c3,
Creator<D> c4,
Creator<E> c5,
Map5<A,B,C,D,E,R> m)
Creates a Component object which takes instances created from five other Creator object and transforms them to a new Object. |
|
static
|
map(Creator<A> c1,
Creator<B> c2,
Creator<C> c3,
Creator<D> c4,
Map4<A,B,C,D,R> m)
Creates a Component object which takes instances created from four other Creator object and transforms them to a new Object. |
|
static
|
map(Creator<A> c1,
Creator<B> c2,
Creator<C> c3,
Map3<A,B,C,R> m)
Creates a Component object which takes instances created from three other Creator object and transforms them to a new Object. |
|
static
|
map(Creator<A> c1,
Creator<B> c2,
Map2<A,B,R> m)
Creates a Component object which takes instances created from two other Creator object and transforms them to a new Object. |
|
static
|
map(Creator<From> cc,
Map<From,To> m)
Customizes a Component object so that upon creation, the new Component object transforms the result component instance to another instance. |
|
static
|
mplus(Creator<T> c1,
Creator<T> c2)
The monadic mplus operation, when the first component fails with resolution error, an alternative component is tried instead. |
|
static Component |
mzero()
Create a monadic mzero Component that always fails. |
|
static
|
onException(java.lang.Class<? extends java.lang.Throwable> type,
Creator<T> creator)
Create a Recovery object that will recover from a provided exception type by returning an alternative Creator object. |
|
static ComponentBinder |
pass()
Create a ComponentBinder object that always returns the same object passed in. |
|
static
|
recover(Creator<T> c1,
Recovery<T> r)
Create a new Component object that will recover errors happened from the provided Component. |
|
static
|
seq(Creator<A> c1,
Creator<B> c2)
Monadic 'sequence' operation. |
|
static
|
sequence(Creator<T>... ccs)
Monadic 'sequence' operator that sequentially execute an array of components and keep the result of the last one. |
|
static
|
toComponentBinder(Binder<From,To> b)
Convert a Binder object to a ComponentBinder object by making the verification do nothing. |
|
static
|
toVerificationBinder(Creator<T> c)
Create a ComponentBinder object that uses a Creator object for instantiation and verification regardless of the input. |
|
static Verifiable |
verifyAs(java.lang.Class t)
Create a Verifiable object that always succeed with a given result type. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Monad()
| Method Detail |
|---|
public static <From,To> Component<To> bind(Creator<From> c1,
ComponentBinder<From,To> binder)
1. invokes the Creator object to create an instance.
2. feed the instance to the Binder object to get a second Creator object.
3. Invoke the second Creator object to get a second instance.
4. return the second instance as the instance of this Component.
c1 - the Component object.binder - the Binder object that also takes care of dynamic verification.
public static <From,To> Component<To> bind(Creator<From> c1,
Binder<From,To> binder)
1. invokes the Creator object to create an instance.
2. feed the instance to the Binder object to get a second Creator object.
3. Invoke the second Creator object to get a second instance.
4. return the second instance as the instance of this Component.
c1 - the Creator object.binder - the Binder object.
public static <A,B> Component<B> seq(Creator<A> c1,
Creator<B> c2)
c1 - the first component.c2 - the second component.
public static <T> Component<T> sequence(Creator<T>... ccs)
ccs - the array of the components.
public static <From,To> Component<To> map(Creator<From> cc,
Map<From,To> m)
cc - the Component object to customize.m - the Map object to transform component instance.
public static <A,B,R> Component<R> map(Creator<A> c1,
Creator<B> c2,
Map2<A,B,R> m)
c1 - the first Creator object.c2 - the second Creator object.m - the Map2 object to transform.
public static <A,B,C,R> Component<R> map(Creator<A> c1,
Creator<B> c2,
Creator<C> c3,
Map3<A,B,C,R> m)
c1 - the first Creator object.c2 - the second Creator object.c3 - the third Creator object.m - the Map3 object to transform.
public static <A,B,C,D,R> Component<R> map(Creator<A> c1,
Creator<B> c2,
Creator<C> c3,
Creator<D> c4,
Map4<A,B,C,D,R> m)
c1 - the first Creator object.c2 - the second Creator object.c3 - the third Creator object.c4 - the fourth Creator object.m - the Map4 object to transform.
public static <A,B,C,D,E,R> Component<R> map(Creator<A> c1,
Creator<B> c2,
Creator<C> c3,
Creator<D> c4,
Creator<E> c5,
Map5<A,B,C,D,E,R> m)
c1 - the first Creator object.c2 - the second Creator object.c3 - the third Creator object.c4 - the fourth Creator object.c5 - the fifth Creator object.m - the Map5 object to transform.
public static <T> Component<T> mplus(Creator<T> c1,
Creator<T> c2)
c1 - the first creator.c2 - the alternative creator.
public static Component fail(java.lang.String msg)
msg - the error message when fails.
public static Component mzero()
public static <T> Component<T> recover(Creator<T> c1,
Recovery<T> r)
c1 - the Component to recover.r - the Recovery object.
public static <T> Recovery<T> onException(java.lang.Class<? extends java.lang.Throwable> type,
Creator<T> creator)
type - the exception type.creator - the alternative Creator object.
public static <T> Component<T> followedBy(Component<T> c1,
ComponentBinder<T,?> binder)
ComponentBinder object is used
to do certain side-effect to complete the work.
The object created by the base component is finally returned as the instance.
ComponentBinder object also takes care of verification
of the base component type.
c1 - the base component.binder - the ComponentBinder object to do the side effect.
public static <T> Component<T> followedBy(Component<T> c1,
Binder<T,?> binder)
Binder object is used
to do certain side-effect to complete the work.
The object created by the base component is finally returned as the instance.
c1 - the base component.binder - the Binder object to do the side effect.
public static <T> Component<T> followedBy(Component<T> c1,
Creator<?> c2)
c1 - the base component.c2 - the Component object to do the side-effect.
public static ComponentBinder pass()
public static ComponentBinder instantiator()
public static <From,To> ComponentBinder<From,To> toComponentBinder(Binder<From,To> b)
b - the Binder object.
public static <x,T> ComponentBinder<x,T> toVerificationBinder(Creator<T> c)
c - the Component object.
public static <T> Component<T> ifelse(Creator<java.lang.Boolean> cond,
Component<T> a,
Component<T> b)
cond - the Component returning a Boolean value.a - the Component when the condition is true.b - the Component when the condition is false;
public static Verifiable verifyAs(java.lang.Class t)
t - the result type.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||