T
- Type of value storable in this Evalpublic interface Eval<T> extends To<Eval<T>>, Function0<T>, Deconstruct.Deconstruct1<T>, Zippable<T>, MonadicValue<T>, Higher<DataWitness.eval,T>
public void odd(){
System.out.println(even(Eval.now(200000)).getValue());
}
public Eval<String> odd(Eval<Integer> n ) {
return n.flatMap(x->even(Eval.now(x-1)));
}
public Eval<String> even(Eval<Integer> n ) {
return n.flatMap(x->{
return x<=0 ? Eval.now("done") : odd(Eval.now(x-1));
});
}
Modifier and Type | Interface and Description |
---|---|
static class |
Eval.CompletableEval<ORG,T2> |
static class |
Eval.Comprehensions |
static class |
Eval.Module |
Function0.FunctionalOperations<R>
Deconstruct.Deconstruct1<T1>, Deconstruct.Deconstruct2<T1,T2>, Deconstruct.Deconstruct3<T1,T2,T3>, Deconstruct.Deconstruct4<T1,T2,T3,T4>, Deconstruct.Deconstruct5<T1,T2,T3,T4,T5>
Modifier and Type | Method and Description |
---|---|
static <T,R> Eval<R> |
accumulate(java.lang.Iterable<Eval<T>> evals,
java.util.function.Function<? super T,R> mapper,
Monoid<R> reducer)
Sequence and reduce an Iterable of Evals into an Eval with a reduced value
|
static <T,R> Eval<R> |
accumulate(java.lang.Iterable<Eval<T>> evals,
Reducer<R,T> reducer)
Sequence and reduce a CollectionX of Evals into an Eval with a reduced value
|
static <T> Eval<T> |
accumulate(Monoid<T> reducer,
java.lang.Iterable<Eval<T>> evals) |
static <T> Eval<T> |
always(java.util.function.Supplier<T> value)
Lazily create an Eval from the specified Supplier.
|
static <T> Eval<T> |
async(java.util.concurrent.Executor ex,
java.util.function.Supplier<T> s) |
static <T> Eval<T> |
coeval(Future<Eval<T>> pub) |
default Eval<T> |
combineEager(Monoid<T> monoid,
MonadicValue<? extends T> v2) |
default <R> Eval<R> |
concatMap(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> mapper)
A flattening transformation operation that takes the first value from the returned Iterable.
|
static <T> Eval<T> |
defer(java.util.function.Supplier<Eval<T>> value) |
default <R> Eval<R> |
emptyUnit() |
static <T> Eval.CompletableEval<T,T> |
eval()
Create a reactive CompletableEval
|
default Maybe<T> |
filter(java.util.function.Predicate<? super T> pred)
Keep only elements for which the supplied predicates hold
e.g.
|
default Maybe<T> |
filterNot(java.util.function.Predicate<? super T> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<R> Eval<R> |
flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper)
A flattening transformation operation (@see
Optional.flatMap(Function) |
default <R> R |
fold(java.util.function.Function<? super T,? extends R> present,
java.util.function.Supplier<? extends R> absent) |
default <R1,R> Eval<R> |
forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied MonadicValue
|
default <R1,R> Eval<R> |
forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,java.lang.Boolean> filterFunction,
java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied stream
|
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Function3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
Perform a three level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Function3<? super T,? super R1,? super R2,java.lang.Boolean> filterFunction,
Function3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
Perform a three level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Function3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Function4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
Perform a four level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Function3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Function4<? super T,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction,
Function4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
Perform a four level nested internal iteration over this MonadicValue and the
supplied MonadicValues
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c<100,
(a,b,c,d)->a+b+c+d);
//Maybe.none
|
static <T> Eval<T> |
fromFuture(Future<T> pub) |
static <T> Eval<T> |
fromIterable(java.lang.Iterable<T> iterable)
Create an Eval instance from an Iterable
|
static <T> Eval<T> |
fromPublisher(org.reactivestreams.Publisher<T> pub)
Create an Eval instance from a reactive-streams publisher
|
T |
get() |
static <T> Eval<T> |
later(java.util.function.Supplier<T> value)
Lazily create an Eval from the specified Supplier.
|
default <R> Eval<R> |
map(java.util.function.Function<? super T,? extends R> mapper)
Transform this functor using the supplied transformation function
|
default <R> Eval<R> |
mergeMap(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
A flattening transformation operation that takes the first value from the returned Publisher.
|
static <R> Eval<R> |
narrow(Eval<? extends R> broad)
Narrow covariant type parameter
|
static <T> Eval<T> |
narrowK(Higher<DataWitness.eval,T> future)
Convert the raw Higher Kinded Type for Evals types into the Eval interface
|
default Maybe<T> |
notNull()
Filter elements retaining only values which are not null
|
static <T> Eval<T> |
now(T value)
Create an Eval with the value specified
|
default <U> Maybe<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
default Eval<T> |
peek(java.util.function.Consumer<? super T> c)
Peek at the current value of this Transformable, without transforming it
|
static <T> Eval<ReactiveSeq<T>> |
sequence(java.lang.Iterable<? extends Eval<T>> evals)
Turn a toX of Evals into a single Eval with a List of values.
|
static <T> Eval<ReactiveSeq<T>> |
sequence(ReactiveSeq<? extends Eval<T>> stream) |
static <T> Eval<ReactiveSeq<T>> |
sequence(java.util.stream.Stream<? extends Eval<T>> evals)
Turn a Stream of Evals into a single Eval with a Stream of values.
|
default ReactiveSeq<T> |
stream() |
default ReactiveSeq<T> |
streamUntil(long time,
java.util.concurrent.TimeUnit unit) |
default ReactiveSeq<T> |
streamUntil(java.util.function.Predicate<? super T> p) |
default ReactiveSeq<T> |
streamWhile(java.util.function.Predicate<? super T> p) |
static <T,R> Eval<R> |
tailRec(T initial,
java.util.function.Function<? super T,? extends Eval<? extends Either<T,R>>> fn) |
default Future<T> |
toFuture() |
default Maybe<T> |
toMaybe() |
default Trampoline<T> |
toTrampoline() |
static <T,R> Eval<ReactiveSeq<R>> |
traverse(java.util.function.Function<? super T,? extends R> fn,
ReactiveSeq<Eval<T>> stream) |
default Tuple1<T> |
unapply() |
<T> Eval<T> |
unit(T unit) |
static <T> Higher<DataWitness.eval,T> |
widen(Eval<T> narrow) |
default <T2,R> Eval<R> |
zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn,
org.reactivestreams.Publisher<? extends T2> app)
Zip (combine) this Zippable with the supplied Publisher, using the supplied combining function
|
default <T2,R> Eval<R> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Iterable using the supplied combining function
|
default <U> Eval<Tuple2<T,U>> |
zip(java.lang.Iterable<? extends U> other) |
default <S,U> Eval<Tuple3<T,S,U>> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third) |
default <S,U,R> Eval<R> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third,
Function3<? super T,? super S,? super U,? extends R> fn3) |
default <T2,T3,T4> Eval<Tuple4<T,T2,T3,T4>> |
zip4(java.lang.Iterable<? extends T2> second,
java.lang.Iterable<? extends T3> third,
java.lang.Iterable<? extends T4> fourth) |
default <T2,T3,T4,R> |
zip4(java.lang.Iterable<? extends T2> second,
java.lang.Iterable<? extends T3> third,
java.lang.Iterable<? extends T4> fourth,
Function4<? super T,? super T2,? super T3,? super T4,? extends R> fn) |
default <U> Eval<Tuple2<T,U>> |
zipWithPublisher(org.reactivestreams.Publisher<? extends U> other) |
andThen, apply, apply, coflatMapFn, flatMapFn, fnTo, functionOps, future, generate, iterate, lazyLift, lift, lift, liftTry, mapFn, memoize, memoize, memoizeAsync, memoizeAsync, toEval, toType, λ, λ, λv
fold
arity, attemptMap, mapAsync, mapRetry, mapRetry, mapTry, mapTry
asSupplier, collect, fold, forEach, generate, isPresent, iterate, iterator, mkString, newSubscriber, nonEmptyList, nonEmptyListGet, orElse, orElseGet, print, print, printErr, printOut, subscribe, toEither, toLazyEither, toLeft, toOption, toOptional, toRight, toTry, toTry, toTry, transform
static <T,R> Eval<R> tailRec(T initial, java.util.function.Function<? super T,? extends Eval<? extends Either<T,R>>> fn)
static <T> Higher<DataWitness.eval,T> widen(Eval<T> narrow)
static <T> Eval<T> async(java.util.concurrent.Executor ex, java.util.function.Supplier<T> s)
static <T> Eval<T> narrowK(Higher<DataWitness.eval,T> future)
future
- HKT encoded list into a OptionalTypestatic <T> Eval<T> fromPublisher(org.reactivestreams.Publisher<T> pub)
Eval<Integer> e = Eval.fromPublisher(Mono.just(10));
//Eval[10]
pub
- Publisher to create the Eval fromstatic <T> Eval.CompletableEval<T,T> eval()
CompletableEval<Integer,Integer> completable = Eval.eval();
Eval<Integer> mapped = completable.map(i->i*2)
.flatMap(i->Eval.later(()->i+1));
completable.complete(5);
mapped.printOut();
//11
T
- Data input type to the Evaldefault ReactiveSeq<T> streamWhile(java.util.function.Predicate<? super T> p)
default ReactiveSeq<T> streamUntil(java.util.function.Predicate<? super T> p)
default ReactiveSeq<T> streamUntil(long time, java.util.concurrent.TimeUnit unit)
default ReactiveSeq<T> stream()
static <T> Eval<T> fromIterable(java.lang.Iterable<T> iterable)
Eval<Integer> e = Eval.fromIterable(Arrays.asList(10));
//Eval[10]
iterable
- to create the Eval fromstatic <T> Eval<T> now(T value)
Eval<Integer> e = Eval.now(10);
//Eval[10]
value
- of Evalstatic <T> Eval<T> later(java.util.function.Supplier<T> value)
Eval<Integer> e = Eval.later(()->10)
.map(i->i*2);
//Eval[20] - maybe so will not be executed until the value is accessed
value
- Supplier to (lazily) populate this Evalstatic <T> Eval<T> always(java.util.function.Supplier<T> value)
Eval<Integer> e = Eval.always(()->10)
.map(i->i*2);
//Eval[20] - maybe so will not be executed until the value is accessed
value
- Supplier to (lazily) populate this Evalstatic <T> Eval<ReactiveSeq<T>> sequence(java.lang.Iterable<? extends Eval<T>> evals)
Eval<Seq<Integer>> maybes =Eval.sequence(Seq.of(Eval.now(10),Eval.now(1)));
//Eval.now(Seq.of(10,1)));
evals
- Collection of evals to convert into a single eval with a List of valuesstatic <T> Eval<ReactiveSeq<T>> sequence(java.util.stream.Stream<? extends Eval<T>> evals)
Eval<ReactiveSeq<Integer>> maybes =Eval.sequence(Stream.of(Eval.now(10),Eval.now(1)));
//Eval.now(ReactiveSeq.of(10,1)));
evals
- Collection of evals to convert into a single eval with a List of valuesstatic <T> Eval<ReactiveSeq<T>> sequence(ReactiveSeq<? extends Eval<T>> stream)
static <T,R> Eval<ReactiveSeq<R>> traverse(java.util.function.Function<? super T,? extends R> fn, ReactiveSeq<Eval<T>> stream)
static <T,R> Eval<R> accumulate(java.lang.Iterable<Eval<T>> evals, Reducer<R,T> reducer)
Eval<PersistentSetX<Integer>> accumulated = Eval.accumulate(Seq.of(just,Eval.now(1)),Reducers.toPersistentSetX());
//Eval.now(PersistentSetX.of(10,1)))
evals
- Collection of Evals to accumulatereducer
- Reducer to fold nest values intostatic <T,R> Eval<R> accumulate(java.lang.Iterable<Eval<T>> evals, java.util.function.Function<? super T,R> mapper, Monoid<R> reducer)
Eval<String> evals =Eval.accumulate(Seq.of(just,Eval.later(()->1)),i->""+i,Monoids.stringConcat);
//Eval.now("101")
evals
- Collection of Evals to accumulatemapper
- Funtion to transform Eval contents to type required by Semigroup accumulatorreducer
- Combiner function to applyHKT to converted valuesdefault Trampoline<T> toTrampoline()
<T> Eval<T> unit(T unit)
default <R> Eval<R> map(java.util.function.Function<? super T,? extends R> mapper)
Transformable
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface MonadicValue<T>
map
in interface Transformable<T>
mapper
- Transformation function<R> Eval<R> flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper)
MonadicValue
Optional.flatMap(Function)
Eval.now(1).map(i->i+2).flatMap(i->Eval.later(()->i*3);
//Eval[9]
flatMap
in interface MonadicValue<T>
mapper
- transformation functiondefault <R> Eval<R> concatMap(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> mapper)
MonadicValue
Maybe.just(1).map(i->i+2).concatMap(i->Arrays.asList(()->i*3,20);
//Maybe[9]
concatMap
in interface MonadicValue<T>
mapper
- transformation functiondefault <R> Eval<R> mergeMap(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
MonadicValue
Future.ofResult(1).map(i->i+2).mergeMap(i->Flux.just(()->i*3,20);
//Future[9]
mergeMap
in interface MonadicValue<T>
mapper
- transformation functiondefault <U> Maybe<U> ofType(java.lang.Class<? extends U> type)
Filters
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
default Maybe<T> filterNot(java.util.function.Predicate<? super T> fn)
Filters
of(1,2,3).filter(i->i>2);
//[1,2]
default Maybe<T> notNull()
Filters
of(1,2,null,4).nonNull();
//[1,2,4]
default Maybe<T> filter(java.util.function.Predicate<? super T> pred)
Filters
of(1,2,3).filter(i->i>2);
//[3]
default Eval<T> peek(java.util.function.Consumer<? super T> c)
Transformable
of(1,2,3).map(System.out::println)
1
2
3
peek
in interface Transformable<T>
c
- Consumer that recieves each element from this Transformabledefault <R> R fold(java.util.function.Function<? super T,? extends R> present, java.util.function.Supplier<? extends R> absent)
static <R> Eval<R> narrow(Eval<? extends R> broad)
broad
- Eval with covariant type parameterdefault <T2,R> Eval<R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippable
default <T2,R> Eval<R> zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
Zippable
default <U> Eval<Tuple2<T,U>> zipWithPublisher(org.reactivestreams.Publisher<? extends U> other)
zipWithPublisher
in interface Zippable<T>
default <S,U> Eval<Tuple3<T,S,U>> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third)
default <S,U,R> Eval<R> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third, Function3<? super T,? super S,? super U,? extends R> fn3)
default <T2,T3,T4> Eval<Tuple4<T,T2,T3,T4>> zip4(java.lang.Iterable<? extends T2> second, java.lang.Iterable<? extends T3> third, java.lang.Iterable<? extends T4> fourth)
default <T2,T3,T4,R> Eval<R> zip4(java.lang.Iterable<? extends T2> second, java.lang.Iterable<? extends T3> third, java.lang.Iterable<? extends T4> fourth, Function4<? super T,? super T2,? super T3,? super T4,? extends R> fn)
default <T2,R1,R2,R3,R> Eval<R> forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Function3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3, Function4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c+d);
//Maybe.none
forEach4
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overvalue3
- Nested MonadicValue to iterate overyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R3,R> Eval<R> forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Function3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3, Function4<? super T,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction, Function4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c<100,
(a,b,c,d)->a+b+c+d);
//Maybe.none
forEach4
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overvalue3
- Nested MonadicValue to iterate overfilterFunction
- Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R> Eval<R> forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Function3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach3(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->a+b+c<100,
(a,b,c)->a+b+c);
//Maybe[32]
forEach3
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R> Eval<R> forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Function3<? super T,? super R1,? super R2,java.lang.Boolean> filterFunction, Function3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach3(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->a+b+c<100,
(a,b,c)->a+b+c);
//Maybe[32]
forEach3
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overfilterFunction
- Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <R1,R> Eval<R> forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
(a,b)->a+b);
//Maybe.none()
forEach2
in interface MonadicValue<T>
value1
- Nested Monadic Type to iterate overyieldingFunction
- Function with pointers to the current element from both
monad types that generates the new elementsdefault <R1,R> Eval<R> forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,java.lang.Boolean> filterFunction, java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
a->b-> a<3 && b>10,
(a,b)->a+b);
//Maybe.none()
forEach2
in interface MonadicValue<T>
value1
- Nested monadic type to iterate overfilterFunction
- Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
Streams that generates the new elementsdefault <R> Eval<R> emptyUnit()