T
- Current input type of FunctionR
- Current return type of Functionpublic interface Reader<T,R> extends Fn1<T,R>, Transformable<R>
For comprehension with the Reader Monad, using curried syntax :-
import com.aol.cyclops2.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;
}
Fn1.µ, Fn1.FunctionalOperations<T1,R>
Modifier and Type | Method and Description |
---|---|
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,R4> Reader<T,R4> |
forEach2(java.util.function.Function<? super R,Reader<T,R1>> value2,
java.util.function.BiFunction<? super R,? super R1,? extends R4> yieldingFunction)
Perform a For Comprehension over a Reader, accepting a generating function.
|
default <R1,R2,R4> Reader<T,R4> |
forEach3(java.util.function.Function<? super R,? extends Reader<T,R1>> value2,
java.util.function.BiFunction<? super R,? super R1,? extends Reader<T,R2>> value3,
Fn3<? super R,? super R1,? super R2,? extends R4> yieldingFunction)
Perform a For Comprehension over a Reader, accepting 2 generating function.
|
default <R1,R2,R3,R4> |
forEach4(java.util.function.Function<? super R,? extends Reader<T,R1>> value2,
java.util.function.BiFunction<? super R,? super R1,? extends Reader<T,R2>> value3,
Fn3<? super R,? super R1,? super R2,? extends Reader<T,R3>> value4,
Fn4<? super R,? super R1,? super R2,? super R3,? extends R4> yieldingFunction) |
default <R1> Reader<T,R1> |
map(java.util.function.Function<? super R,? extends R1> f2)
Transform this functor using the supplied transformation function
|
andThen, andThen, apply, bind, compose, functionOps, lift, lift, liftF, liftOpt, liftTry, memoize, memoize, product, reader, λ, λv
apply, applyPartially, applyPartially, curry, curry, from, toFunction
cast, peek, retry, retry, trampoline
default <R1> Reader<T,R1> map(java.util.function.Function<? super R,? extends R1> f2)
Transformable
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface Transformable<R>
f2
- Transformation functiondefault <R1> Reader<T,R1> flatMap(java.util.function.Function<? super R,? extends Reader<T,R1>> f)
f
- Transformation function to be flatteneddefault <R1,R2,R3,R4> Reader<T,R4> forEach4(java.util.function.Function<? super R,? extends Reader<T,R1>> value2, java.util.function.BiFunction<? super R,? super R1,? extends Reader<T,R2>> value3, Fn3<? super R,? super R1,? super R2,? extends Reader<T,R3>> value4, Fn4<? super R,? super R1,? super R2,? super R3,? extends R4> yieldingFunction)
default <R1,R2,R4> Reader<T,R4> forEach3(java.util.function.Function<? super R,? extends Reader<T,R1>> value2, java.util.function.BiFunction<? super R,? super R1,? extends Reader<T,R2>> value3, Fn3<? super R,? super R1,? super R2,? extends R4> yieldingFunction)
import static com.aol.cyclops2.reactor.Readers.forEach3;
forEach3(Reader.just(1),
a-> Reader.just(a+1),
(a,b) -> Reader.<Integer>just(a+b),
Tuple::tuple)
value1
- top level Readervalue2
- Nested Readervalue3
- Nested ReaderyieldingFunction
- Generates a result per combinationdefault <R1,R4> Reader<T,R4> forEach2(java.util.function.Function<? super R,Reader<T,R1>> value2, java.util.function.BiFunction<? super R,? super R1,? extends R4> yieldingFunction)
import static com.aol.cyclops2.reactor.Readers.forEach;
forEach(Reader.just(1),
a-> Reader.just(a+1),
Tuple::tuple)
value1
- top level Readervalue2
- Nested ReaderyieldingFunction
- Generates a result per combination