public class MonoTValue<A> extends java.lang.Object implements MonoT<A>, TransformerValue<A>, MonadicValue<A>, java.util.function.Supplier<A>, ConvertableFunctor<A>, Filterable<A>, ApplicativeFunctor<A>, Matchable.ValueAndOptionalMatcher<A>
ApplicativeFunctor.Applicatives, ApplicativeFunctor.ApplyFunctions<T>Value.ValueImpl<T>Convertable.SupplierToConvertable<T>| Modifier and Type | Method and Description |
|---|---|
<B> MonoTValue<B> |
bind(java.util.function.Function<? super A,MonoT<? extends B>> f)
FlatMap operation
|
<U> MonoTValue<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException. |
<R> MonoTValue<R> |
coflatMap(java.util.function.Function<? super MonadicValue<A>,R> mapper)
Perform a coflatMap operation.
|
<T2,R> MonoTValue<R> |
combine(Value<? extends T2> app,
java.util.function.BiFunction<? super A,? super T2,? extends R> fn)
Lazily combine this ApplicativeFunctor with the supplied value via the supplied BiFunction
Example
|
MonoTValue<A> |
combineEager(Monoid<A> monoid,
MonadicValue<? extends A> v2)
Eagerly combine two MonadicValues using the supplied monoid (@see ApplicativeFunctor for type appropraite i.e.
|
<R> MonoTValue<R> |
empty() |
boolean |
equals(java.lang.Object o) |
MonoTValue<A> |
filter(java.util.function.Predicate<? super A> test)
Keep only elements for which the supplied predicates hold
e.g.
|
MonoTValue<A> |
filterNot(java.util.function.Predicate<? super A> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<B> MonoTValue<B> |
flatMap(java.util.function.Function<? super A,? extends MonadicValue<? extends B>> f)
flatMap operation
|
<B> MonoTValue<B> |
flatMapT(java.util.function.Function<? super A,MonoTValue<B>> f)
Flat Map the wrapped CompletableFuture
|
static <A> MonoTValue<A> |
fromAnyM(AnyMValue<A> anyM)
|
A |
get() |
int |
hashCode() |
boolean |
isPresent() |
boolean |
isValuePresent() |
java.util.Iterator<A> |
iterator() |
static <U,R> java.util.function.Function<MonoTValue<U>,MonoTValue<R>> |
lift(java.util.function.Function<? super U,? extends R> fn)
Lift a function into one that accepts and returns an CompletableFutureT
This allows multiple monad types to add functionality to existing functions and methods
e.g.
|
static <U1,U2,R> java.util.function.BiFunction<MonoTValue<U1>,MonoTValue<U2>,MonoTValue<R>> |
lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
Lift a BiFunction into one that accepts and returns CompletableFutureTs
This allows multiple monad types to add functionality to existing functions and methods
e.g.
|
<B> MonoTValue<B> |
map(java.util.function.Function<? super A,? extends B> f)
Map the wrapped Mono
|
MonoTValue<MonadicValue<A>> |
nest()
cojoin pattern.
|
MonoTValue<A> |
notNull()
Filter elements retaining only values which are not null
|
static <A> MonoTValue<A> |
of(AnyMValue<reactor.core.publisher.Mono<A>> monads)
Construct an CompletableFutureT from an AnyM that wraps a monad containing CompletableFutures
|
static <A> MonoTValue<A> |
of(reactor.core.publisher.Mono<A> monads) |
<U> MonoTValue<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
<R> MonoTValue<R> |
patternMatch(java.util.function.Function<Matchable.CheckValue1<A,R>,Matchable.CheckValue1<A,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
MonoTValue<A> |
peek(java.util.function.Consumer<? super A> peek)
Peek at the current value of the Mono
|
ReactiveSeq<A> |
stream() |
void |
subscribe(org.reactivestreams.Subscriber<? super A> s) |
boolean |
test(A t) |
java.lang.String |
toString() |
<R> MonoTValue<R> |
trampoline(java.util.function.Function<? super A,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
<R> MonoTValue<R> |
unit(R value) |
AnyMValue<reactor.core.publisher.Mono<A>> |
unwrap() |
FutureW<A> |
value() |
<T2,R> MonoTValue<R> |
zip(java.util.function.BiFunction<? super A,? super T2,? extends R> fn,
org.reactivestreams.Publisher<? extends T2> app)
Zip (combine) this Zippable with the supplied Publisher, using the supplied combining function
|
<T2,R> MonoTValue<R> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super A,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Iterable using the supplied combining function
|
<U> MonoTValue<org.jooq.lambda.tuple.Tuple2<A,U>> |
zip(java.lang.Iterable<? extends U> other)
Zip (combine) this Zippable with the supplied Iterable combining both into a Tuple2
|
<U> MonoTValue<org.jooq.lambda.tuple.Tuple2<A,U>> |
zip(org.jooq.lambda.Seq<? extends U> other)
Zip (combine) this Zippable with the supplied Seq combining both into a Tuple2
|
<U,R> MonoTValue<R> |
zip(org.jooq.lambda.Seq<? extends U> other,
java.util.function.BiFunction<? super A,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Seq, using the supplied combining function
|
<U> MonoTValue<org.jooq.lambda.tuple.Tuple2<A,U>> |
zip(java.util.stream.Stream<? extends U> other)
Zip (combine) this Zippable with the supplied Stream combining both into a Tuple2
|
<U,R> MonoTValue<R> |
zip(java.util.stream.Stream<? extends U> other,
java.util.function.BiFunction<? super A,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Stream, using the supplied combining function
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitemptyList, emptyOptional, fromAnyM, fromAnyMSeq, fromAnyMValue, fromFuture, fromIterable, fromIterableValue, fromMono, fromOptional, fromPublisher, fromStream, fromValue, offutureStream, getStreamable, isEmpty, jdkStream, reactiveSeq, reveresedJDKStream, reveresedStreamanyM, flatMapIterable, flatMapPublisher, forEach2, forEach2, forEach3, forEach3, forEach4, forEach4applyFunctionscollect, fold, fold, generate, iterate, mapReduce, mkString, newSubscriber, of, 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, 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, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptional, toOptionalAtomicReference, toStream, visittoOptional, visitmatchespublic FutureW<A> value()
value in interface TransformerValue<A>public boolean isPresent()
isPresent in interface TransformerValue<A>isPresent in interface Convertable<A>public boolean isValuePresent()
isValuePresent in interface TransformerValue<A>public MonoTValue<A> filter(java.util.function.Predicate<? super A> test)
Filterable
of(1,2,3).filter(i->i>2);
//[3]
filter in interface TransformerValue<A>filter in interface MonoT<A>filter in interface Filterable<A>filter in interface MonadicValue<A>test - to filter elements by, retaining matchespublic MonoTValue<A> peek(java.util.function.Consumer<? super A> peek)
MonoT
MonoT.of(AnyM.fromIterable(ListX.of(Mono.just(10)))
.peek(System.out::println);
//prints 10
public <B> MonoTValue<B> map(java.util.function.Function<? super A,? extends B> f)
MonoT
MonoT.of(AnyM.fromIterable(ListX.of(Mono.just(10)))
.map(t->t+1);
map in interface TransformerValue<A>map in interface MonoT<A>map in interface ConvertableFunctor<A>map in interface Functor<A>map in interface MonadicValue<A>f - Mapping function for the wrapped Monopublic <T2,R> MonoTValue<R> combine(Value<? extends T2> app, java.util.function.BiFunction<? super A,? 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
public <T2,R> MonoTValue<R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super A,? super T2,? extends R> fn)
Zippablepublic <T2,R> MonoTValue<R> zip(java.util.function.BiFunction<? super A,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
Zippablepublic <U,R> MonoTValue<R> zip(org.jooq.lambda.Seq<? extends U> other, java.util.function.BiFunction<? super A,? super U,? extends R> zipper)
Zippablepublic <U,R> MonoTValue<R> zip(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super A,? super U,? extends R> zipper)
Zippablepublic <U> MonoTValue<org.jooq.lambda.tuple.Tuple2<A,U>> zip(java.util.stream.Stream<? extends U> other)
Zippablepublic <U> MonoTValue<org.jooq.lambda.tuple.Tuple2<A,U>> zip(org.jooq.lambda.Seq<? extends U> other)
Zippablepublic <U> MonoTValue<org.jooq.lambda.tuple.Tuple2<A,U>> zip(java.lang.Iterable<? extends U> other)
Zippablepublic <B> MonoTValue<B> flatMapT(java.util.function.Function<? super A,MonoTValue<B>> f)
MonoT.fromOptional(Optional.of(Mono.just(10))
.flatMapT(t->MonoT.fromOptional(Mono.just(t*2));
//MonoT[20]
f - FlatMap functionpublic <B> MonoTValue<B> flatMap(java.util.function.Function<? super A,? extends MonadicValue<? extends B>> f)
MonoT
MonoT.of(AnyM.fromIterable(ListX.of(Mono.just(10)))
.flatMap(t-> Maybe.just(t+1));
public static <U,R> java.util.function.Function<MonoTValue<U>,MonoTValue<R>> lift(java.util.function.Function<? super U,? extends R> fn)
public static <U1,U2,R> java.util.function.BiFunction<MonoTValue<U1>,MonoTValue<U2>,MonoTValue<R>> lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
public static <A> MonoTValue<A> fromAnyM(AnyMValue<A> anyM)
anyM - AnyM that doesn't contain a monad wrapping an CompletableFuturepublic static <A> MonoTValue<A> of(AnyMValue<reactor.core.publisher.Mono<A>> monads)
monads - AnyM that contains a monad wrapping an CompletableFuturepublic static <A> MonoTValue<A> of(reactor.core.publisher.Mono<A> monads)
public java.lang.String toString()
toString in class java.lang.Objectpublic A get()
get in interface Convertable<A>get in interface java.util.function.Supplier<A>public ReactiveSeq<A> stream()
public java.util.Iterator<A> iterator()
iterator in interface Matchable.MatchableOptional<A>iterator in interface Matchable.ValueAndOptionalMatcher<A>iterator in interface Convertable<A>iterator in interface ToStream<A>iterator in interface Value<A>iterator in interface java.lang.Iterable<A>public void subscribe(org.reactivestreams.Subscriber<? super A> s)
public boolean test(A t)
public <R> MonoTValue<R> unit(R value)
unit in interface TransformerValue<A>unit in interface MonadicValue<A>unit in interface Unit<A>public <R> MonoTValue<R> empty()
public <U> MonoTValue<U> cast(java.lang.Class<? extends U> type)
FunctorClassCastException.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)public <R> MonoTValue<R> trampoline(java.util.function.Function<? super A,? 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 TransformerValue<A>trampoline in interface MonoT<A>trampoline in interface Functor<A>mapper - TCO Transformation functionpublic <R> MonoTValue<R> patternMatch(java.util.function.Function<Matchable.CheckValue1<A,R>,Matchable.CheckValue1<A,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 TransformerValue<A>patternMatch in interface MonoT<A>patternMatch in interface Functor<A>case1 - Function to generate a case (or chain of cases as a single case)otherwise - Value if supplied case doesn't matchpublic <U> MonoTValue<U> ofType(java.lang.Class<? extends U> type)
Filterable
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
public MonoTValue<A> filterNot(java.util.function.Predicate<? super A> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
public MonoTValue<A> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
public <B> MonoTValue<B> bind(java.util.function.Function<? super A,MonoT<? extends B>> f)
MonoTpublic MonoTValue<MonadicValue<A>> nest()
MonadicValuenest in interface MonadicValue<A>public <R> MonoTValue<R> coflatMap(java.util.function.Function<? super MonadicValue<A>,R> mapper)
MonadicValue
Maybe.none().coflatMap(m -> m.isPresent() ? m.get() : 10);
//Maybe[10]
coflatMap in interface MonadicValue<A>mapper - Mapping / transformation functionpublic MonoTValue<A> combineEager(Monoid<A> monoid, MonadicValue<? extends A> 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<A>public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Object