T
- Data type of element stored in Maybepublic interface Maybe<T> extends Option<T>
1. Is lazy by default 2. Can operate Reactively (that is respond to data that arrives asynchronously)
Modifier and Type | Interface and Description |
---|---|
static class |
Maybe.CompletableMaybe<ORG,T2> |
static class |
Maybe.Comprehensions |
static class |
Maybe.Just<T> |
static class |
Maybe.Lazy<T> |
static class |
Maybe.Nothing<T> |
Option.None<T>, Option.Some<T>
Modifier and Type | Method and Description |
---|---|
static <T,R> Maybe<R> |
accumulateJust(java.lang.Iterable<Maybe<T>> maybes,
java.util.function.Function<? super T,R> mapper,
Monoid<R> reducer)
Accumulate the results only from those Maybes which have a value present, using the supplied mapping function to
convert the data from each Maybe before reducing them using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
cyclops2.Monoids .. |
static <T,R> Maybe<R> |
accumulateJust(java.lang.Iterable<Maybe<T>> maybes,
Reducer<R,T> reducer)
Accummulating operation using the supplied Reducer (@see cyclops.Reducers).
|
static <T> Maybe<T> |
accumulateJust(Monoid<T> reducer,
java.lang.Iterable<Maybe<T>> maybes)
Accumulate the results only from those Maybes which have a value present, using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
cyclops2.Monoids . |
static <T,R> java.util.function.Function<? super T,? extends Maybe<R>> |
arrow(java.util.function.Function<? super T,? extends R> fn) |
static <T> Maybe<T> |
async(java.util.concurrent.Executor ex,
java.util.function.Supplier<T> s) |
static <T> Maybe<T> |
attempt(CheckedSupplier<T> s) |
default <R> Maybe<R> |
attemptFlatMap(java.util.function.Function<? super T,? extends Option<? extends R>> fn) |
default <R> Maybe<R> |
attemptMap(java.util.function.Function<? super T,? extends R> fn) |
default <R> Maybe<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.
|
default Option<T> |
eager() |
Maybe<T> |
filter(java.util.function.Predicate<? super T> fn)
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> Maybe<R> |
flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper)
A flattening transformation operation (@see
Optional.flatMap(Function) |
<R> R |
fold(java.util.function.Function<? super T,? extends R> some,
java.util.function.Supplier<? extends R> none) |
default <R1,R> Maybe<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> Maybe<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> Maybe<T> |
fromEval(Eval<T> eval)
Construct a Maybe from the supplied Eval
|
static <T> Maybe<T> |
fromEvalNullable(Eval<T> eval) |
static <T> Maybe<T> |
fromEvalOf(Eval<T> eval)
Deprecated.
|
static <T> Maybe<T> |
fromEvalOptional(Eval<java.util.Optional<T>> value) |
static <T> Maybe<T> |
fromFuture(Future<T> future) |
static <T> Maybe<T> |
fromIterable(java.lang.Iterable<T> iterable)
Construct a Maybe that contains a single value extracted from the supplied Iterable
|
static <T> Maybe<T> |
fromLazy(Eval<Maybe<T>> lazy) |
static <T> Maybe<T> |
fromLazyOption(java.util.function.Supplier<Option<T>> value) |
static <T> Maybe<T> |
fromOption(Option<T> opt) |
static <T> Maybe<T> |
fromOptional(java.util.Optional<T> opt)
Construct an equivalent Maybe from the Supplied Optional
|
static <T> Maybe<T> |
fromPublisher(org.reactivestreams.Publisher<T> pub)
Construct a Maybe that contains a single value extracted from the supplied reactive-streams Publisher
|
static <R> Maybe<R> |
fromStream(java.util.stream.Stream<? extends R> apply) |
boolean |
isPresent() |
static <T> Maybe<T> |
just(T value)
Construct an Maybe which contains the provided (non-null) value.
|
default Maybe<T> |
lazy() |
<R> Maybe<R> |
map(java.util.function.Function<? super T,? extends R> mapper)
Transform this functor using the supplied transformation function
|
static <T> Maybe.CompletableMaybe<T,T> |
maybe()
Create a reactive CompletableMaybe
|
default <R> Maybe<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 <T> Maybe<T> |
narrow(Maybe<? extends T> broad)
Narrow covariant type parameter
|
static <T> Maybe<T> |
narrowK(Higher<DataWitness.option,T> future)
Convert the raw Higher Kinded Type for MaybeType types into the MaybeType type definition class
|
static <T> java.util.Optional<T> |
narrowOptional(Higher<DataWitness.option,T> maybe)
Convert the HigherKindedType definition for a Maybe into
|
static <T> Maybe<T> |
nothing() |
default Maybe<T> |
notNull()
Filter elements retaining only values which are not null
|
static <T> Maybe<T> |
of(T value)
Construct an Maybe which contains the provided (non-null) value
Equivalent to @see
just(Object) |
static <T> Maybe<T> |
ofNullable(T value)
Maybe<Integer> maybe = Maybe.ofNullable(null);
//None
Maybe<Integer> maybe = Maybe.ofNullable(10);
//Maybe[10], Some[10]
|
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 Maybe<T> |
orElseUse(Option<T> opt) |
default Maybe<T> |
peek(java.util.function.Consumer<? super T> c)
Peek at the current value of this Transformable, without transforming it
|
Maybe<T> |
recover(java.util.function.Supplier<? extends T> value) |
Maybe<T> |
recover(T value) |
Maybe<T> |
recoverWith(java.util.function.Supplier<? extends Option<T>> fn) |
static <T> Maybe<ReactiveSeq<T>> |
sequence(java.lang.Iterable<? extends Maybe<T>> maybes)
Sequence operation, take a Collection of Maybes and turn it into a Maybe with a Collection
By constrast with
sequenceJust(Iterable) if any Maybe types are None / zero
the return type will be an zero Maybe / None |
static <T> Maybe<ReactiveSeq<T>> |
sequence(ReactiveSeq<? extends Maybe<T>> stream) |
static <T> Maybe<ReactiveSeq<T>> |
sequence(java.util.stream.Stream<? extends Maybe<T>> maybes)
Sequence operation, take a Stream of Maybes and turn it into a Maybe with a Stream
By constrast with
sequenceJust(Iterable) Maybe#zero/ None types are
result in the returned Maybe being Maybe.zero / None |
static <T> Maybe<ReactiveSeq<T>> |
sequenceJust(java.lang.Iterable<? extends Maybe<T>> maybes)
Sequence operation, take a Collection of Maybes and turn it into a Maybe with a Collection
Only successes are retained.
|
static <T,R> Maybe<R> |
tailRec(T initial,
java.util.function.Function<? super T,? extends Maybe<? extends Either<T,R>>> fn) |
default Maybe<T> |
toMaybe() |
default Trampoline<Maybe<T>> |
toTrampoline() |
static <T,R> Maybe<ReactiveSeq<R>> |
traverse(java.util.function.Function<? super T,? extends R> fn,
ReactiveSeq<Maybe<T>> stream) |
default <T> Maybe<T> |
unit(T unit) |
static <T> Higher<DataWitness.option,T> |
widen(Maybe<T> narrow) |
static <C2,T> Higher<C2,Higher<DataWitness.option,T>> |
widen2(Higher<C2,Maybe<T>> nestedMaybe) |
default <T2,R> Maybe<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> Maybe<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> Maybe<Tuple2<T,U>> |
zip(java.lang.Iterable<? extends U> other) |
default <S,U> Maybe<Tuple3<T,S,U>> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third) |
default <S,U,R> Maybe<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> Maybe<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> Maybe<Tuple2<T,U>> |
zipWithPublisher(org.reactivestreams.Publisher<? extends U> other) |
accumulateJust, accumulateJust, accumulateJust, emptyUnit, fromNullable, fromStream, narrow, none, sequence, sequence, sequence, sequenceJust, some, tailRec, traverse, widen, widen2
orElseUse
arity, mapAsync, mapRetry, mapRetry, mapTry, mapTry
asSupplier, collect, fold, forEach, generate, iterate, iterator, mkString, nonEmptyList, nonEmptyListGet, orElse, orElseGet, print, print, printErr, printOut, stream, subscribe, toEither, toLazyEither, toLeft, toOption, toOptional, toRight, toTry, toTry, toTry
static final Maybe EMPTY
static <T> Maybe<T> attempt(CheckedSupplier<T> s)
default <R> Maybe<R> attemptMap(java.util.function.Function<? super T,? extends R> fn)
attemptMap
in interface MonadicValue<T>
default <R> Maybe<R> attemptFlatMap(java.util.function.Function<? super T,? extends Option<? extends R>> fn)
attemptFlatMap
in interface Option<T>
static <T,R> Maybe<R> tailRec(T initial, java.util.function.Function<? super T,? extends Maybe<? extends Either<T,R>>> fn)
static <T> Higher<DataWitness.option,T> widen(Maybe<T> narrow)
static <T> Maybe<T> async(java.util.concurrent.Executor ex, java.util.function.Supplier<T> s)
static <T> Maybe.CompletableMaybe<T,T> maybe()
CompletableMaybe<Integer,Integer> completable = Maybe.maybe();
Maybe<Integer> mapped = completable.map(i->i*2)
.flatMap(i->Eval.later(()->i+1));
completable.complete(5);
mapped.printOut();
//11
CompletableMaybe<Integer,Integer> completable = Maybe.maybe();
Maybe<Integer> mapped = completable.map(i->i*2)
.flatMap(i->Eval.later(()->i+1));
completable.complete(null);
mapped.printOut();
//
//Maybe:None
T
- Data input type to the Maybestatic <T> Maybe<T> fromFuture(Future<T> future)
fromFuture
in interface Option<T>
static <T,R> java.util.function.Function<? super T,? extends Maybe<R>> arrow(java.util.function.Function<? super T,? extends R> fn)
static <C2,T> Higher<C2,Higher<DataWitness.option,T>> widen2(Higher<C2,Maybe<T>> nestedMaybe)
static <T> Maybe<T> narrowK(Higher<DataWitness.option,T> future)
static <T> java.util.Optional<T> narrowOptional(Higher<DataWitness.option,T> maybe)
maybe
- Constructor to convert back into narrowed typestatic <T> Maybe<T> nothing()
default <R> Maybe<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]
default <R> Maybe<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]
static <T> Maybe<T> fromPublisher(org.reactivestreams.Publisher<T> pub)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
Maybe<Integer> maybe = Maybe.fromPublisher(stream);
//Maybe[1]
fromPublisher
in interface Option<T>
pub
- Publisher to extract value fromstatic <T> Maybe<T> fromIterable(java.lang.Iterable<T> iterable)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
Maybe<Integer> maybe = Maybe.fromIterable(stream);
//Maybe[1]
fromIterable
in interface Option<T>
iterable
- Iterable to extract value fromstatic <R> Maybe<R> fromStream(java.util.stream.Stream<? extends R> apply)
static <T> Maybe<T> fromOptional(java.util.Optional<T> opt)
Maybe<Integer> some = Maybe.fromOptional(Optional.of(10));
//Maybe[10], Some[10]
Maybe<Integer> none = Maybe.fromOptional(Optional.zero());
//Maybe.zero, None[]
fromOptional
in interface Option<T>
opt
- Optional to construct Maybe fromdefault Trampoline<Maybe<T>> toTrampoline()
toTrampoline
in interface Option<T>
static <T> Maybe<T> fromEval(Eval<T> eval)
Maybe<Integer> maybe = Maybe.fromEval(Eval.now(10));
//Maybe[10]
Maybe<Integer> maybeNull = Maybe.fromEval(()->null);
//Maybe[null]
eval
- Eval to construct Maybe fromstatic <T> Maybe<T> just(T value)
of(Object)
Maybe<Integer> some = Maybe.just(10);
some.map(i->i*2);
value
- Value to wrap inside a Maybestatic <T> Maybe<T> of(T value)
just(Object)
Maybe<Integer> some = Maybe.of(10);
some.map(i->i*2);
static <T> Maybe<T> ofNullable(T value)
Maybe<Integer> maybe = Maybe.ofNullable(null);
//None
Maybe<Integer> maybe = Maybe.ofNullable(10);
//Maybe[10], Some[10]
ofNullable
in interface Option<T>
value
- static <T> Maybe<T> narrow(Maybe<? extends T> broad)
broad
- Maybe with covariant type parameterstatic <T> Maybe<ReactiveSeq<T>> sequenceJust(java.lang.Iterable<? extends Maybe<T>> maybes)
sequence(Iterable)
Maybe#zero/ None types are
tolerated and ignored.
Maybe<Integer> just = Maybe.of(10);
Maybe<Integer> none = Maybe.none();
Maybe<Seq<Integer>> maybes = Maybe.sequenceJust(Seq.of(just, none, Maybe.of(1)));
//Maybe.of(Seq.of(10, 1));
maybes
- Maybes to Sequencestatic <T> Maybe<ReactiveSeq<T>> sequence(ReactiveSeq<? extends Maybe<T>> stream)
static <T,R> Maybe<ReactiveSeq<R>> traverse(java.util.function.Function<? super T,? extends R> fn, ReactiveSeq<Maybe<T>> stream)
static <T> Maybe<ReactiveSeq<T>> sequence(java.lang.Iterable<? extends Maybe<T>> maybes)
sequenceJust(Iterable)
if any Maybe types are None / zero
the return type will be an zero Maybe / None
Maybe<Integer> just = Maybe.of(10);
Maybe<Integer> none = Maybe.none();
Maybe<Seq<Integer>> maybes = Maybe.sequence(Seq.of(just, none, Maybe.of(1)));
//Maybe.none();
maybes
- Maybes to Sequencestatic <T> Maybe<ReactiveSeq<T>> sequence(java.util.stream.Stream<? extends Maybe<T>> maybes)
sequenceJust(Iterable)
Maybe#zero/ None types are
result in the returned Maybe being Maybe.zero / None
Maybe<Integer> just = Maybe.of(10);
Maybe<Integer> none = Maybe.none();
Maybe<ReactiveSeq<Integer>> maybes = Maybe.sequence(Stream.of(just, none, Maybe.of(1)));
//Maybe.none();
maybes
- Maybes to Sequencestatic <T,R> Maybe<R> accumulateJust(java.lang.Iterable<Maybe<T>> maybes, Reducer<R,T> reducer)
Maybe<Integer> just = Maybe.of(10);
Maybe<Integer> none = Maybe.none();
Maybe<PersistentSetX<Integer>> maybes = Maybe.accumulateJust(Seq.of(just, none, Maybe.of(1)), Reducers.toPersistentSetX());
//Maybe.of(PersistentSetX.of(10, 1)));
maybes
- Maybes to accumulatereducer
- Reducer to accumulate values withstatic <T,R> Maybe<R> accumulateJust(java.lang.Iterable<Maybe<T>> maybes, java.util.function.Function<? super T,R> mapper, Monoid<R> reducer)
cyclops2.Monoids
..
Maybe<Integer> just = Maybe.of(10);
Maybe<Integer> none = Maybe.none();
Maybe<String> maybes = Maybe.accumulateJust(Seq.of(just, none, Maybe.of(1)), i -> "" + i,
SemigroupK.stringConcat);
//Maybe.of("101")
maybes
- Maybes to accumulatemapper
- Mapping function to be applied to the result of each Maybereducer
- Monoid to combine values from each Maybestatic <T> Maybe<T> accumulateJust(Monoid<T> reducer, java.lang.Iterable<Maybe<T>> maybes)
cyclops2.Monoids
.
Maybe<Integer> maybes = Maybe.accumulateJust(Monoids.intSum,Seq.of(just, none, Maybe.of(1)));
//Maybe.of(11)
maybes
- Maybes to accumulatereducer
- Monoid to combine values from each Maybedefault <U> Maybe<Tuple2<T,U>> zipWithPublisher(org.reactivestreams.Publisher<? extends U> other)
zipWithPublisher
in interface Option<T>
zipWithPublisher
in interface Zippable<T>
default <S,U> Maybe<Tuple3<T,S,U>> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third)
default <S,U,R> Maybe<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> Maybe<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> Maybe<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> Maybe<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>
forEach4
in interface Option<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> Maybe<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>
forEach4
in interface Option<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> Maybe<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>
forEach3
in interface Option<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> Maybe<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>
forEach3
in interface Option<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> Maybe<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>
forEach2
in interface Option<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> Maybe<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>
forEach2
in interface Option<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 <T2,R> Maybe<R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippable
default <T2,R> Maybe<R> zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
Zippable
default <T> Maybe<T> unit(T unit)
boolean isPresent()
Maybe<T> recoverWith(java.util.function.Supplier<? extends Option<T>> fn)
recoverWith
in interface Option<T>
<R> Maybe<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 Option<T>
map
in interface Transformable<T>
mapper
- Transformation function<R> Maybe<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]
<R> R fold(java.util.function.Function<? super T,? extends R> some, java.util.function.Supplier<? extends R> none)
Maybe<T> filter(java.util.function.Predicate<? super T> fn)
Filters
of(1,2,3).filter(i->i>2);
//[3]
default <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> peek(java.util.function.Consumer<? super T> c)
Transformable
of(1,2,3).map(System.out::println)
1
2
3