T - Data type of element stored in Maybepublic interface Maybe<T> extends To<Maybe<T>>, MonadicValue<T>, Zippable<T>, java.util.function.Supplier<T>, ConvertableFunctor<T>, Filterable<T>, ApplicativeFunctor<T>, Matchable.ValueAndOptionalMatcher<T>
//eagerly load data
Optional.of(10)
.map(this::load);
//lazily tee up loading of data until needed
Maybe.of(10)
.map(this::load);
.
Maybe is tail recursive
{@code| Modifier and Type | Interface and Description |
|---|---|
static class |
Maybe.Just<T> |
static class |
Maybe.Lazy<T> |
static class |
Maybe.Nothing<T> |
ApplicativeFunctor.Applicatives, ApplicativeFunctor.ApplyFunctions<T>Value.ValueImpl<T>Convertable.SupplierToConvertable<T>| Modifier and Type | Method and Description |
|---|---|
static <T,R> Maybe<R> |
accumulateJust(CollectionX<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)
Monoids.. |
static <T,R> Maybe<R> |
accumulateJust(CollectionX<Maybe<T>> maybes,
Reducer<R> reducer)
Accummulating operation using the supplied Reducer (@see com.aol.cyclops.Reducers).
|
static <T> Maybe<T> |
accumulateJust(Monoid<T> reducer,
CollectionX<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)
Monoids. |
default <U> Maybe<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException. |
default <R> Maybe<R> |
coflatMap(java.util.function.Function<? super MonadicValue<T>,R> mapper)
Perform a coflatMap operation.
|
default Maybe<T> |
combine(java.util.function.BinaryOperator<Combiner<T>> combiner,
Combiner<T> app)
Combine two applicatives together using the provided BinaryOperator (Semigroup, Monoid and Reducer all
extend BinaryOperator - checkout Semigroups and Monoids for a large number of canned combinations).
|
default <T2,R> Maybe<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
Example
|
default Maybe<T> |
combineEager(Monoid<T> monoid,
MonadicValue<? extends T> v2)
Eagerly combine two MonadicValues using the supplied monoid (@see ApplicativeFunctor for type appropraite i.e.
|
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) |
default <R> Maybe<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> Maybe<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.
|
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,
TriFunction<? 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,
TriFunction<? super T,? super R1,? super R2,java.lang.Boolean> filterFunction,
TriFunction<? 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,
TriFunction<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3,
QuadFunction<? 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,
TriFunction<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3,
QuadFunction<? super T,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction,
QuadFunction<? 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> |
fromIterable(java.lang.Iterable<T> iterable)
Construct a Maybe that contains a single value extracted from the supplied Iterable
|
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
|
boolean |
isPresent() |
static <T> Maybe<T> |
just(T value)
Construct an Maybe which contains the provided (non-null) value.
|
<R> Maybe<R> |
map(java.util.function.Function<? super T,? extends R> mapper)
Transform this functor using the supplied transformation function
|
static <T> Maybe<T> |
narrow(Maybe<? extends T> broad)
Narrow covariant type parameter
|
default Maybe<MonadicValue<T>> |
nest()
cojoin pattern.
|
static <T> Maybe<T> |
none() |
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 <R> Maybe<R> |
patternMatch(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
default Maybe<T> |
peek(java.util.function.Consumer<? super T> c)
Peek at the current value of this Functor, without transforming it
|
Maybe<T> |
recover(java.util.function.Supplier<T> value) |
Maybe<T> |
recover(T value) |
static <T> Maybe<ListX<T>> |
sequence(CollectionX<Maybe<T>> maybes)
Sequence operation, take a Collection of Maybes and turn it into a Maybe with a Collection
By constrast with
sequenceJust(CollectionX) if any Maybe types are None / empty
the return type will be an empty Maybe / None |
static <T> Maybe<ReactiveSeq<T>> |
sequence(java.util.stream.Stream<Maybe<T>> maybes)
Sequence operation, take a Stream of Maybes and turn it into a Maybe with a Stream
By constrast with
sequenceJust(CollectionX) Maybe#empty/ None types are
result in the returned Maybe being Maybe.empty / None |
static <T> Maybe<ListX<T>> |
sequenceJust(CollectionX<Maybe<T>> maybes)
Sequence operation, take a Collection of Maybes and turn it into a Maybe with a Collection
Only successes are retained.
|
default Maybe<T> |
toMaybe()
Returns a function result or a supplier result.
|
default <R> Maybe<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
|
default <T> Maybe<T> |
unit(T unit) |
<R> R |
visit(java.util.function.Function<? super T,? extends R> some,
java.util.function.Supplier<? extends R> none)
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> 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<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> Maybe<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> Maybe<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> Maybe<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> Maybe<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
|
anyMapplyFunctionscollect, fold, fold, generate, iterate, iterator, mapReduce, mkString, newSubscriber, stream, subscribe, test, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFeatureToggle, toFutureStream, toFutureStream, toIor, toLazyImmutable, toList, toListX, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry, toXor, toXor, unapplyendsWith, 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, xMatchcollect, fromSupplier, get, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptional, toOptionalAtomicReference, toStreamiterator, toOptionalmatchesstatic final Maybe EMPTY
static <T> Maybe<T> none()
default <R> Maybe<R> flatMapIterable(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> mapper)
MonadicValue
Maybe.just(1).map(i->i+2).flatMapIterable(i->Arrays.asList(()->i*3,20);
//Maybe[9]
flatMapIterable in interface MonadicValue<T>mapper - transformation functiondefault <R> Maybe<R> flatMapPublisher(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
MonadicValue
FutureW.ofResult(1).map(i->i+2).flatMapPublisher(i->Flux.just(()->i*3,20);
//FutureW[9]
flatMapPublisher in interface MonadicValue<T>mapper - transformation functionstatic <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]
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]
iterable - Iterable to extract value fromstatic <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.empty());
//Maybe.empty, None[]
opt - Optional to construct Maybe fromstatic <T> Maybe<T> fromEval(Eval<T> eval)
Maybe<Integer> maybe = Maybe.fromEval(Eval.now(10));
//Maybe[10]
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]
value - static <T> Maybe<T> narrow(Maybe<? extends T> broad)
broad - Maybe with covariant type parameterstatic <T> Maybe<ListX<T>> sequenceJust(CollectionX<Maybe<T>> maybes)
sequence(CollectionX) Maybe#empty/ None types are
tolerated and ignored.
Maybe<Integer> just = Maybe.of(10);
Maybe<Integer> none = Maybe.none();
Maybe<ListX<Integer>> maybes = Maybe.sequenceJust(ListX.of(just, none, Maybe.of(1)));
//Maybe.of(ListX.of(10, 1));
maybes - Maybes to Sequencestatic <T> Maybe<ListX<T>> sequence(CollectionX<Maybe<T>> maybes)
sequenceJust(CollectionX) if any Maybe types are None / empty
the return type will be an empty Maybe / None
Maybe<Integer> just = Maybe.of(10);
Maybe<Integer> none = Maybe.none();
Maybe<ListX<Integer>> maybes = Maybe.sequence(ListX.of(just, none, Maybe.of(1)));
//Maybe.none();
maybes - Maybes to Sequencestatic <T> Maybe<ReactiveSeq<T>> sequence(java.util.stream.Stream<Maybe<T>> maybes)
sequenceJust(CollectionX) Maybe#empty/ None types are
result in the returned Maybe being Maybe.empty / 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(CollectionX<Maybe<T>> maybes, Reducer<R> reducer)
Maybe<Integer> just = Maybe.of(10);
Maybe<Integer> none = Maybe.none();
Maybe<PSetX<Integer>> maybes = Maybe.accumulateJust(ListX.of(just, none, Maybe.of(1)), Reducers.toPSetX());
//Maybe.of(PSetX.of(10, 1)));
maybes - Maybes to accumulatereducer - Reducer to accumulate values withstatic <T,R> Maybe<R> accumulateJust(CollectionX<Maybe<T>> maybes, java.util.function.Function<? super T,R> mapper, Monoid<R> reducer)
Monoids..
Maybe<Integer> just = Maybe.of(10);
Maybe<Integer> none = Maybe.none();
Maybe<String> maybes = Maybe.accumulateJust(ListX.of(just, none, Maybe.of(1)), i -> "" + i,
Semigroups.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, CollectionX<Maybe<T>> maybes)
Monoids.
Maybe<Integer> maybes = Maybe.accumulateJust(Monoids.intSum,ListX.of(just, none, Maybe.of(1)));
//Maybe.of(11)
maybes - Maybes to accumulatereducer - Monoid to combine values from each Maybedefault <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, TriFunction<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3, QuadFunction<? 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> 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, TriFunction<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3, QuadFunction<? super T,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction, QuadFunction<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValueMaybe.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 apply 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, TriFunction<? 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> 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, TriFunction<? super T,? super R1,? super R2,java.lang.Boolean> filterFunction, TriFunction<? 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 apply 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>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>filterFunction - Filter to apply 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> combine(Value<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Combiner
Maybe<Integer> some = Maybe.just(10);
just.combine(Eval.now(20), this::add);
//Some[30]
Maybe<Integer> none = Maybe.none();
none.combine(Eval.now(20), this::add);
//None
default <T2,R> Maybe<R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippabledefault <T2,R> Maybe<R> zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
Zippabledefault Maybe<T> combine(java.util.function.BinaryOperator<Combiner<T>> combiner, Combiner<T> app)
Combinercombine in interface Combiner<T>Semigroup,
Semigroups,
Monoid,
To lift any Semigroup (or monoid) up to handling Applicatives use the combineApplicatives operator in Semigroups
{@see com.aol.cyclops.Semigroups#combineApplicatives(BiFunction) } or Monoids
{ {@see com.aol.cyclops.Monoids#combineApplicatives(java.util.function.Function, com.aol.cyclops.Monoid)
}
{@code
BinaryOperator> sumMaybes = Semigroups.combineScalarFunctors(Semigroups.intSum);
Maybe.just(1)
.combine(sumMaybes, Maybe.just(5))
//Maybe.just(6));
}
default <U,R> Maybe<R> zip(org.jooq.lambda.Seq<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zippabledefault <U,R> Maybe<R> zip(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zippabledefault <U> Maybe<org.jooq.lambda.tuple.Tuple2<T,U>> zip(java.util.stream.Stream<? extends U> other)
Zippabledefault <U> Maybe<org.jooq.lambda.tuple.Tuple2<T,U>> zip(org.jooq.lambda.Seq<? extends U> other)
Zippabledefault <U> Maybe<org.jooq.lambda.tuple.Tuple2<T,U>> zip(java.lang.Iterable<? extends U> other)
Zippabledefault <T> Maybe<T> unit(T unit)
default <R> Maybe<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>mapper - Mapping / transformation functiondefault Maybe<MonadicValue<T>> nest()
MonadicValuenest in interface MonadicValue<T>default Maybe<T> combineEager(Monoid<T> monoid, MonadicValue<? extends T> v2)
MonadicValue
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 MonadicValue<T>default Maybe<T> toMaybe()
Valueboolean isPresent()
isPresent in interface Convertable<T><R> Maybe<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>mapper - Transformation function<R> Maybe<R> flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper)
MonadicValueOptional.flatMap(Function)
Eval.now(1).map(i->i+2).flatMap(i->Eval.later(()->i*3);
//Eval[9]
flatMap in interface MonadicValue<T>mapper - transformation function<R> R visit(java.util.function.Function<? super T,? extends R> some, java.util.function.Supplier<? extends R> none)
Visitablevisit in interface Convertable<T>visit in interface Matchable.MatchableOptional<T>visit in interface Matchable.ValueAndOptionalMatcher<T>visit in interface Visitable<T>some - Function to execute if this Visitable has a valuenone - Supplier to execute if this Visitable does not have a ValueMaybe<T> filter(java.util.function.Predicate<? super T> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[3]
filter in interface Filterable<T>filter in interface MonadicValue<T>fn - to filter elements by, retaining matchesdefault <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 <U> Maybe<U> cast(java.lang.Class<? extends U> type)
FunctorClassCastException.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default Maybe<T> peek(java.util.function.Consumer<? super T> c)
Functor
of(1,2,3).map(System.out::println)
1
2
3
default <R> Maybe<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> Maybe<R> patternMatch(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,R>> case1, java.util.function.Supplier<? extends R> otherwise)
Functor
List<String> result = CollectionX.of(1,2,3,4)
.patternMatch(
c->c.valuesWhere(i->"even", (Integer i)->i%2==0 )
)
// CollectionX["odd","even","odd","even"]
patternMatch in interface Functor<T>case1 - Function to generate a case (or chain of cases as a single case)otherwise - Value if supplied case doesn't match