T
- Type of value storable in this Evalpublic interface Eval<T> extends java.util.function.Supplier<T>, MonadicValue1<T>, Functor<T>, Filterable<T>, ApplicativeFunctor<T>, Matchable.ValueAndOptionalMatcher<T>
public void odd(){
System.out.println(even(Eval.now(200000)).get());
}
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.Module |
ApplicativeFunctor.Applicatives, ApplicativeFunctor.ApplyFunctions<T>
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Modifier and Type | Method and Description |
---|---|
static <T,R> Eval<R> |
accumulate(CollectionX<Eval<T>> evals,
java.util.function.Function<? super T,R> mapper,
Semigroup<R> reducer)
Sequence and reduce a CollectionX of Evals into an Eval with a reduced value
|
static <T,R> Eval<R> |
accumulate(CollectionX<Eval<T>> evals,
Reducer<R> reducer)
Sequence and reduce a CollectionX of Evals into an Eval with a reduced value
|
static <T> Eval<T> |
accumulate(CollectionX<Eval<T>> evals,
Semigroup<T> reducer)
Sequence and reduce a CollectionX of Evals into an Eval with a reduced value
|
static <T> Eval<T> |
always(java.util.function.Supplier<T> value)
Lazily create an Eval from the specified Supplier.
|
default <U> Eval<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
default <R> Eval<R> |
coflatMap(java.util.function.Function<? super MonadicValue<T>,R> mapper)
Perform a coflatMap operation.
|
default <T2,R> Eval<R> |
combine(Value<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Lazily combine this ApplicativeFunctor with the supplied value via the supplied BiFunction
|
default Eval<T> |
combineEager(Monoid<T> monoid,
MonadicValue<? extends T> v2)
Eagerly combine two MonadicValues using the supplied monoid (@see ApplicativeFunctor for type appropraite i.e.
|
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> Eval<R> |
flatMapIterable(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.
|
default <R> Eval<R> |
flatMapPublisher(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 <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.
|
<R> Eval<R> |
map(java.util.function.Function<? super T,? extends R> mapper)
Transform this functor using the supplied transformation function
|
static <R> Eval<R> |
narrow(Eval<? extends R> broad)
Narrow covariant type parameter
|
default Eval<MonadicValue<T>> |
nest()
cojoin pattern.
|
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 Functor, without transforming it
|
static <T> Eval<ListX<T>> |
sequence(CollectionX<Eval<T>> evals)
Turn a collection of Evals into a single Eval with a List of values.
|
static <T> Eval<ReactiveSeq<T>> |
sequence(java.util.stream.Stream<Eval<T>> evals)
Turn a Stream of Evals into a single Eval with a Stream of values.
|
default PVectorX<java.util.function.Function<java.lang.Object,java.lang.Object>> |
steps() |
default <R> Eval<R> |
trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
<T> Eval<T> |
unit(T unit) |
default <R> R |
visit(java.util.function.Function<? super T,? extends R> present,
java.util.function.Supplier<? extends R> absent)
The provided function is executed with the value stored in this Visitable if one is present,
otherwise the provided Supplier is executed instead.
|
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<org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(java.lang.Iterable<? extends U> other)
Zip (combine) this Zippable with the supplied Iterable combining both into a Tuple2
|
default <U> Eval<org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(org.jooq.lambda.Seq<? extends U> other)
Zip (combine) this Zippable with the supplied Seq combining both into a Tuple2
|
default <U,R> Eval<R> |
zip(org.jooq.lambda.Seq<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Seq, using the supplied combining function
|
default <U> Eval<org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(java.util.stream.Stream<? extends U> other)
Zip (combine) this Zippable with the supplied Stream combining both into a Tuple2
|
default <U,R> Eval<R> |
zip(java.util.stream.Stream<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Stream, using the supplied combining function
|
anyM
applyFunctions
collect, fold, fold, generate, iterate, iterator, mapReduce, mkString, newSubscriber, of, stream, subscribe, test, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFeatureToggle, toFutureStream, toFutureStream, toIor, toLazyImmutable, toList, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry, toXor, toXor, unapply
endsWith, endsWithIterable, findAny, findFirst, firstValue, foldable, foldRight, foldRight, foldRight, foldRightMapToType, get, groupBy, join, join, join, mapReduce, print, print, printErr, printOut, reduce, reduce, reduce, reduce, reduce, reduce, reduce, schedule, scheduleFixedDelay, scheduleFixedRate, single, single, singleOptional, startsWith, startsWithIterable, toConcurrentLazyCollection, toConcurrentLazyStreamable, toLazyCollection, validate, xMatch
collect, fromSupplier, isPresent, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptional, toOptionalAtomicReference, toStream
iterator, toOptional
matches
static <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<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] - lazy 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] - lazy so will not be executed until the value is accessed
value
- Supplier to (lazily) populate this Evalstatic <T> Eval<ListX<T>> sequence(CollectionX<Eval<T>> evals)
Eval<ListX<Integer>> maybes =Eval.sequence(ListX.of(Eval.now(10),Eval.now(1)));
//Eval.now(ListX.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<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,R> Eval<R> accumulate(CollectionX<Eval<T>> evals, Reducer<R> reducer)
Eval<PSetX<Integer>> accumulated = Eval.accumulate(ListX.of(just,Eval.now(1)),Reducers.toPSetX());
//Eval.now(PSetX.of(10,1)))
evals
- Collection of Evals to accumulatereducer
- Reducer to fold nested values intostatic <T,R> Eval<R> accumulate(CollectionX<Eval<T>> evals, java.util.function.Function<? super T,R> mapper, Semigroup<R> reducer)
Eval<String> evals =Eval.accumulate(ListX.of(just,Eval.later(()->1)),i->""+i,Semigroups.stringConcat);
//Eval.now("101")
evals
- Collection of Evals to accumulatemapper
- Funtion to map Eval contents to type required by Semigroup accumulatorreducer
- Combiner function to apply to converted valuesstatic <T> Eval<T> accumulate(CollectionX<Eval<T>> evals, Semigroup<T> reducer)
Eval<Integer> maybes =Eval.accumulate(ListX.of(just,Eval.now(1)),Semigroups.intSum);
//Eval.now(11)
evals
- Collection of Evals to accumulatereducer
- Combiner function to apply to converted values<T> Eval<T> unit(T unit)
unit
in interface MonadicValue<T>
unit
in interface MonadicValue1<T>
unit
in interface Unit<T>
<R> Eval<R> map(java.util.function.Function<? super T,? extends R> mapper)
Functor
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface ConvertableFunctor<T>
map
in interface Functor<T>
map
in interface MonadicValue<T>
map
in interface MonadicValue1<T>
mapper
- Transformation function<R> Eval<R> flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper)
MonadicValue1
Optional.flatMap(Function)
Eval.now(1).map(i->i+2).flatMap(i->Eval.later(()->i*3);
//Eval[9]
flatMap
in interface MonadicValue1<T>
mapper
- transformation functiondefault PVectorX<java.util.function.Function<java.lang.Object,java.lang.Object>> steps()
default <R> Eval<R> coflatMap(java.util.function.Function<? super MonadicValue<T>,R> mapper)
MonadicValue
Maybe.none().coflatMap(m -> m.isPresent() ? m.get() : 10);
//Maybe[10]
coflatMap
in interface MonadicValue<T>
coflatMap
in interface MonadicValue1<T>
mapper
- Mapping / transformation functiondefault Eval<T> combineEager(Monoid<T> monoid, MonadicValue<? extends T> v2)
MonadicValue1
Monoid<Integer> add = Monoid.of(1,Semigroups.intSum);
Maybe.of(10).combineEager(add,Maybe.none());
//Maybe[10]
Maybe.none().combineEager(add,Maybe.of(10));
//Maybe[10]
Maybe.none().combineEager(add,Maybe.none());
//Maybe.none()
Maybe.of(10).combineEager(add,Maybe.of(10));
//Maybe[20]
Monoid<Integer> firstNonNull = Monoid.of(null , Semigroups.firstNonNull());
Maybe.of(10).combineEager(firstNonNull,Maybe.of(10));
//Maybe[10]
combineEager
in interface MonadicValue1<T>
default <R> Eval<R> flatMapIterable(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> mapper)
MonadicValue1
Maybe.just(1).map(i->i+2).flatMapIterable(i->Arrays.asList(()->i*3,20);
//Maybe[9]
flatMapIterable
in interface MonadicValue1<T>
mapper
- transformation functiondefault <R> Eval<R> flatMapPublisher(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
MonadicValue1
FutureW.ofResult(1).map(i->i+2).flatMapPublisher(i->Flux.just(()->i*3,20);
//FutureW[9]
flatMapPublisher
in interface MonadicValue1<T>
mapper
- transformation functiondefault Eval<MonadicValue<T>> nest()
MonadicValue
nest
in interface MonadicValue<T>
T get()
get
in interface Convertable<T>
get
in interface java.util.function.Supplier<T>
default <U> Maybe<U> ofType(java.lang.Class<? extends U> type)
Filterable
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
ofType
in interface Filterable<T>
default Maybe<T> filterNot(java.util.function.Predicate<? super T> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
filterNot
in interface Filterable<T>
fn
- to filter elements by, retaining matchesdefault Maybe<T> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
notNull
in interface Filterable<T>
default Maybe<T> filter(java.util.function.Predicate<? super T> pred)
Filterable
of(1,2,3).filter(i->i>2);
//[3]
filter
in interface Filterable<T>
pred
- to filter elements by, retaining matchesdefault <U> Eval<U> cast(java.lang.Class<? extends U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default Eval<T> peek(java.util.function.Consumer<? super T> c)
Functor
of(1,2,3).map(System.out::println)
1
2
3
default <R> Eval<R> trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Functor
ReactiveSeq.of(10,20,30,40)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
Trampoline<Long> fibonacci(int i){
return fibonacci(i,1,0);
}
Trampoline<Long> fibonacci(int n, long a, long b) {
return n == 0 ? Trampoline.done(b) : Trampoline.more( ()->fibonacci(n-1, a+b, a));
}
55
6765
832040
102334155
ReactiveSeq.of(10_000,200_000,3_000_000,40_000_000)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
completes successfully
trampoline
in interface Functor<T>
mapper
- TCO Transformation functiondefault <R> R visit(java.util.function.Function<? super T,? extends R> present, java.util.function.Supplier<? extends R> absent)
Visitable
visit
in interface Convertable<T>
visit
in interface Matchable.MatchableOptional<T>
visit
in interface Matchable.ValueAndOptionalMatcher<T>
visit
in interface Visitable<T>
present
- Function to execute if this Visitable has a valueabsent
- Supplier to execute if this Visitable does not have a Valuestatic <R> Eval<R> narrow(Eval<? extends R> broad)
broad
- Eval with covariant type parameterdefault <T2,R> Eval<R> combine(Value<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
ApplicativeFunctor
combine
in interface ApplicativeFunctor<T>
app
- Value to combine with this one.fn
- BiFunction to combine themdefault <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,R> Eval<R> zip(org.jooq.lambda.Seq<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zippable
default <U,R> Eval<R> zip(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zippable
default <U> Eval<org.jooq.lambda.tuple.Tuple2<T,U>> zip(java.util.stream.Stream<? extends U> other)
Zippable
default <U> Eval<org.jooq.lambda.tuple.Tuple2<T,U>> zip(org.jooq.lambda.Seq<? extends U> other)
Zippable