A - public interface MonoT<A> extends Unit<A>, org.reactivestreams.Publisher<A>, Functor<A>, Filterable<A>, ToStream<A>
| Modifier and Type | Method and Description |
|---|---|
default <B> MonoT<B> |
bind(java.util.function.Function<? super A,MonoT<? extends B>> f)
FlatMap operation
|
default <U> MonoT<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException. |
<R> MonoT<R> |
empty() |
static <T> MonoTSeq<T> |
emptyList() |
static <T> MonoTValue<T> |
emptyOptional() |
MonoT<A> |
filter(java.util.function.Predicate<? super A> test)
Keep only elements for which the supplied predicates hold
e.g.
|
default MonoT<A> |
filterNot(java.util.function.Predicate<? super A> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<B> MonoT<B> |
flatMap(java.util.function.Function<? super A,? extends MonadicValue<? extends B>> f)
flatMap operation
|
static <A> MonoT<A> |
fromAnyM(AnyM<A> anyM)
|
static <A> MonoTSeq<A> |
fromAnyMSeq(AnyMSeq<A> anyM)
Create a MonoT from an AnyMSeq by wrapping the elements stored in the AnyMSeq in a Mono
|
static <A> MonoTValue<A> |
fromAnyMValue(AnyMValue<A> anyM)
Create a MonoT from an AnyMValue by wrapping the element stored in the AnyMValue in a Mono
|
static <A> MonoTValue<A> |
fromFuture(java.util.concurrent.CompletableFuture<reactor.core.publisher.Mono<A>> future)
Construct a MonoTValue from an CompletableFuture containing a Mono
|
static <A> MonoTSeq<A> |
fromIterable(java.lang.Iterable<reactor.core.publisher.Mono<A>> iterableOfMonos)
Create a MonoTSeq from an Iterable that contains nested Monos
|
static <A> MonoTValue<A> |
fromIterableValue(java.lang.Iterable<reactor.core.publisher.Mono<A>> iterableOfMonos)
Construct a MonoTValue from an Iterable containing a Mono
|
static <A> MonoTValue<A> |
fromMono(reactor.core.publisher.Mono<reactor.core.publisher.Mono<A>> mono)
Construct a MonoTValue from a Mono containing a Mono
|
static <A> MonoTValue<A> |
fromOptional(java.util.Optional<reactor.core.publisher.Mono<A>> optional)
Construct a MonoTValue from an Optional containing a Mono
|
static <A> MonoTSeq<A> |
fromPublisher(org.reactivestreams.Publisher<reactor.core.publisher.Mono<A>> publisherOfMonos)
Construct a MonoTSeq from a Publisher containing Monos
|
static <A> MonoTSeq<A> |
fromStream(java.util.stream.Stream<reactor.core.publisher.Mono<A>> streamOfMonos)
Construct a MonoTSeq from a Stream of Monos
|
static <A,V extends MonadicValue<reactor.core.publisher.Mono<A>>> |
fromValue(V monadicValue)
Construct a MonoTValue from a cyclops-react MonadicValue (Maybe, Eval FutureW etc) containing a Mono
|
static <U,R> java.util.function.Function<MonoT<U>,MonoT<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<MonoT<U1>,MonoT<U2>,MonoT<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> MonoT<B> |
map(java.util.function.Function<? super A,? extends B> f)
Map the wrapped Mono
|
default MonoT<A> |
notNull()
Filter elements retaining only values which are not null
|
static <A> MonoT<A> |
of(AnyM<reactor.core.publisher.Mono<A>> monads)
Construct an MonoT from an AnyM that wraps a monad containing Monos
|
default <U> MonoT<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
default <R> MonoT<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
|
MonoT<A> |
peek(java.util.function.Consumer<? super A> peek)
Peek at the current value of the Mono
|
default <R> MonoT<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
|
AnyM<reactor.core.publisher.Mono<A>> |
unwrap() |
futureStream, getStreamable, isEmpty, iterator, jdkStream, reactiveSeq, reveresedJDKStream, reveresedStream, streamMonoT<A> filter(java.util.function.Predicate<? super A> test)
Filterable
of(1,2,3).filter(i->i>2);
//[3]
filter in interface Filterable<A>test - to filter elements by, retaining matches<R> MonoT<R> empty()
default <B> MonoT<B> bind(java.util.function.Function<? super A,MonoT<? extends B>> f)
f - Mapping functionstatic <A> MonoT<A> of(AnyM<reactor.core.publisher.Mono<A>> monads)
MonoT<Integer> monoT = MonoT.of(AnyM.fromOptional(Optional.of(Mono.just(10)));
monads - AnyM that contains a monad wrapping an MonoMonoT<A> peek(java.util.function.Consumer<? super A> peek)
MonoT.of(AnyM.fromIterable(ListX.of(Mono.just(10)))
.peek(System.out::println);
//prints 10
<B> MonoT<B> map(java.util.function.Function<? super A,? extends B> f)
MonoT.of(AnyM.fromIterable(ListX.of(Mono.just(10)))
.map(t->t+1);
<B> MonoT<B> flatMap(java.util.function.Function<? super A,? extends MonadicValue<? extends B>> f)
MonoT.of(AnyM.fromIterable(ListX.of(Mono.just(10)))
.flatMap(t-> Maybe.just(t+1));
f - Mapping functionstatic <U,R> java.util.function.Function<MonoT<U>,MonoT<R>> lift(java.util.function.Function<? super U,? extends R> fn)
fn - Function to enhance with functionality from CompletableFuture and another monad typestatic <U1,U2,R> java.util.function.BiFunction<MonoT<U1>,MonoT<U2>,MonoT<R>> lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
fn - BiFunction to enhance with functionality from CompletableFuture and another monad typestatic <A> MonoT<A> fromAnyM(AnyM<A> anyM)
anyM - AnyM that doesn't contain a monad wrapping an Monostatic <A> MonoTValue<A> fromAnyMValue(AnyMValue<A> anyM)
anyM - Monad to embed a Mono inside (wrapping it's current value)static <A> MonoTSeq<A> fromAnyMSeq(AnyMSeq<A> anyM)
anyM - Monad to embed a Mono inside (wrapping it's current values individually in Monos)static <A> MonoTSeq<A> fromIterable(java.lang.Iterable<reactor.core.publisher.Mono<A>> iterableOfMonos)
MonoTSeq<Integer> monoT = MonoT.fromIterable(Arrays.asList(Mono.just(1));
iterableOfMonos - An Iterable containing nested Monosstatic <A> MonoTSeq<A> fromStream(java.util.stream.Stream<reactor.core.publisher.Mono<A>> streamOfMonos)
MonoTSeq<Integer> monoT = MonoT.fromStream(Stream.of(Mono.just(1));
streamOfMonos - Stream containing nested Monosstatic <A> MonoTSeq<A> fromPublisher(org.reactivestreams.Publisher<reactor.core.publisher.Mono<A>> publisherOfMonos)
MonoTSeq<Integer> monoT = MonoT.fromPublisher(Flux.just(Mono.just(1));
publisherOfMonos - Publisher containing nested Monosstatic <A,V extends MonadicValue<reactor.core.publisher.Mono<A>>> MonoTValue<A> fromValue(V monadicValue)
MonoTValue<Integer> monoT = MonoT.fromValue(Maybe.just(Mono.just(1));
monadicValue - MonadicValue containing a nested Monostatic <A> MonoTValue<A> fromOptional(java.util.Optional<reactor.core.publisher.Mono<A>> optional)
MonoTValue<Integer> monoT = MonoT.fromOptional(Optional.of(Mono.just(1));
optional - Optional containing a nested Monostatic <A> MonoTValue<A> fromFuture(java.util.concurrent.CompletableFuture<reactor.core.publisher.Mono<A>> future)
MonoTValue<Integer> monoT = MonoT.fromFuture(CompletableFuture.completedFuture(Mono.just(1));
future - Future containing a nested Monostatic <A> MonoTValue<A> fromMono(reactor.core.publisher.Mono<reactor.core.publisher.Mono<A>> mono)
MonoTValue<Integer> monoT = MonoT.fromFuture(Mono.just(Mono.just(1));
future - Mono containing a nested Monostatic <A> MonoTValue<A> fromIterableValue(java.lang.Iterable<reactor.core.publisher.Mono<A>> iterableOfMonos)
MonoTValue<Integer> monoT = MonoT.fromIterableValue(Arrays.asList(Mono.just(1));
iterableOfMonos - An Iterable containing a Monostatic <T> MonoTValue<T> emptyOptional()
static <T> MonoTSeq<T> emptyList()
default <U> MonoT<U> cast(java.lang.Class<? extends U> type)
FunctorClassCastException.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default <R> MonoT<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 Functor<A>mapper - TCO Transformation functiondefault <R> MonoT<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 Functor<A>case1 - Function to generate a case (or chain of cases as a single case)otherwise - Value if supplied case doesn't matchdefault <U> MonoT<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<A>default MonoT<A> filterNot(java.util.function.Predicate<? super A> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
filterNot in interface Filterable<A>fn - to filter elements by, retaining matchesdefault MonoT<A> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
notNull in interface Filterable<A>