T
- Current input type of FunctionR
- Current return type of Functionpublic interface Reader<T,R> extends java.util.function.Function<T,R>, Functor<R>
For comprehension with the Reader Monad, using curried syntax :-
import com.aol.cyclops.control.For;
Reader<UserRepository,Integer> res = For.reader(depth1("bob"))
.reader(a->depth2("bob"))
.reader(a->b->depth3("bob"))
.reader(a->b->c->depth3("bob"))
.reader(a->b->c->d->depth4("bob"))
.reader(a->b->c->d->e->depth5("bob"))
.reader(a->b->c->d->e->f->depth5("bob"))
.reader(a->b->c->d->e->f->g->depth6("bob"))
.yield(a->b->c->d->e->f->g->h->a+b+c+d+e+f+g+h).unwrap();
res.apply(new UserRepositoryImpl())
//29
private Reader<UserRepository,Integer> depth8(String name){
return repo->depth7(name).apply(repo)+1;
}
Modifier and Type | Method and Description |
---|---|
default AnyM<R> |
anyM() |
default <R1> Reader<T,R1> |
flatMap(java.util.function.Function<? super R,? extends Reader<T,R1>> f)
FlatMap this Reader by applying the prodived function and unnesting to a single Reader
|
default <R1> Reader<T,R1> |
map(java.util.function.Function<? super R,? extends R1> f2)
Transform this functor using the supplied transformation function
|
cast, patternMatch, peek, trampoline
default <R1> Reader<T,R1> map(java.util.function.Function<? super R,? extends R1> f2)
Functor
of(1,2,3).map(i->i*2)
//[2,4,6]
default <R1> Reader<T,R1> flatMap(java.util.function.Function<? super R,? extends Reader<T,R1>> f)
f
- Transformation function to be flattened