T
- type data wrapped by the underlying monadpublic interface AnyM<T> extends Unwrapable, To<AnyM<T>>, EmptyUnit<T>, Unit<T>, Foldable<T>, Functor<T>, FlatMap<T>, ToStream<T>
AnyMValue
and @see AnyMSeq
.
AnyMValue is used to represent Monads that wrap a single value such as Optional
, CompletableFuture
, Maybe
, Eval
, Xor
, Try
, Ior
, FeatureToggle
AnyMSeq is used to represent Monads that wrap an aggregation of values such as Stream
, LazyFutureStream
, List
, Set
, Streamable
Use AnyM to create your monad wrapper.
AnyM.fromXXXX methods can create the appropriate AnyM type for a range of known monad types.
AnyMValue<String> monad1 = AnyM.fromOptional(Optional.of("hello"));
AnyMSeq<String> monad2 = AnyM.fromStream(Stream.of("hello","world"));
Wrapped monads can be unwrapped via the unwrap method, or converted to the desired type via toXXXX methodsModifier and Type | Interface and Description |
---|---|
static class |
AnyM.AnyMFactory |
Modifier and Type | Method and Description |
---|---|
AnyM<java.util.List<T>> |
aggregate(AnyM<T> next)
Aggregate the contents of this Monad and the supplied Monad
|
<R> AnyM<R> |
bind(java.util.function.Function<? super T,?> fn)
Perform a looser typed flatMap / bind operation
The return type can be another type other than the host type
Note the modified javaslang monad laws are not applied during the looser typed bind operation
The modification being used to work around the limits of the Java type system.
|
<R,A> R |
collect(java.util.stream.Collector<? super T,A,R> collector)
Collect the contents of the monad wrapped by this AnyM into supplied collector
A mutable reduction operation equivalent to Stream#collect
|
<T> AnyM<T> |
empty()
Construct an AnyM wrapping a new empty instance of the wrapped type
e.g.
|
default <T> Unit<T> |
emptyUnit() |
default boolean |
eqv(AnyM<T> t)
Tests for equivalency between two AnyM types
|
AnyM<T> |
filter(java.util.function.Predicate<? super T> p)
Perform a filter operation on the wrapped monad instance e.g.
|
<R> AnyM<R> |
flatMapFirst(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> fn)
Perform a flatMap operation that will only work as normal for AnyMSeq types, but for AnyMValue (which can only hold a single value)
will take the first value from the Iterable returned.
|
<R> AnyM<R> |
flatMapFirstPublisher(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> fn)
Perform a flatMap operation that will only work as normal for AnyMSeq types, but for AnyMValue (which can only hold a single value)
will take the first value from the Publisher returned.
|
<T1> AnyM<T1> |
flatten()
join / flatten one level of a nested hierarchy
|
static <T> AnyMSeq<T> |
fromArray(T... streamData)
Create an AnyM wrapping a Stream of the supplied data
|
static <T> AnyMValue<T> |
fromCompletableFuture(java.util.concurrent.CompletableFuture<T> future)
Create an AnyM instance that wraps a CompletableFuture
|
static <T> AnyMSeq<T> |
fromCompletableFutureTSeq(CompletableFutureTSeq<T> futureT)
Create an AnyMSeq instance that wraps an CompletableFutureTransformer
CompletableFutureTSeq |
static <T> AnyMValue<T> |
fromCompletableFutureTValue(CompletableFutureTValue<T> futureT)
Create an AnyMValue instance that wraps an CompletableFutureTransformer
CompletableFutureTValue |
static AnyMSeq<java.lang.Double> |
fromDoubleStream(java.util.stream.DoubleStream stream)
Create an AnyM instance that wraps an DoubleStream
|
static <T> AnyMValue<T> |
fromEval(Eval<T> eval)
Create an AnyMValue instance that wraps an Eval
|
static <T> AnyMSeq<T> |
fromEvalTSeq(EvalTSeq<T> evalT)
Create an AnyMSeq instance that wraps an EvalTransformer
EvalTSeq |
static <T> AnyMValue<T> |
fromEvalTValue(EvalTValue<T> evalT)
Create an AnyMValue instance that wraps an EvalTransformer
EvalTValue |
static <T> AnyMValue<T> |
fromFeatureToggle(FeatureToggle<T> featureToggle)
Create an AnyMValue instance that wraps an FeatureToggle
|
static <T> AnyMValue<T> |
fromFutureW(FutureW<T> future)
Create an AnyMValue instance that wraps a FutureW
|
static <T> AnyMSeq<T> |
fromFutureWTSeq(FutureWTSeq<T> futureT)
Create an AnyMSeq instance that wraps an FutureWTransformer
FutureWTSeq |
static <T> AnyMValue<T> |
fromFutureWTValue(FutureWTValue<T> futureT)
Create an AnyMValue instance that wraps an FutureWTransformer
FutureWTSeq |
static AnyMSeq<java.lang.Integer> |
fromIntStream(java.util.stream.IntStream stream)
Create an AnyM instance that wraps an IntStream
|
static <T> AnyMValue<T> |
fromIor(Ior<?,T> ior)
Create an AnyMValue instance that wraps an Ior
|
static <T> AnyMSeq<T> |
fromIterable(java.lang.Iterable<T> iterable)
Create an AnyM instance that wraps an Iterable
|
static <T> AnyMValue<T> |
fromIterableValue(java.lang.Iterable<T> iterable)
Use this method to create an AnyMValue from an Iterable.
|
static <T> AnyMSeq<T> |
fromList(java.util.List<T> list)
Create an AnyM from a List
This AnyM will convert the List to a Stream under the covers, but will rematerialize the Stream as List
if wrap() is called
|
static <T> AnyMSeq<T> |
fromListT(ListT<T> listT)
Create an AnyMSeq instance that wraps an ListTransformer
ListTSeq |
static AnyMSeq<java.lang.Long> |
fromLongStream(java.util.stream.LongStream stream)
Create an AnyM instance that wraps an LongStream
|
static <T> AnyMValue<T> |
fromMaybe(Maybe<T> maybe)
Create an AnyMValue instance that wraps a
Maybe |
static <T> AnyMSeq<T> |
fromMaybeTSeq(MaybeTSeq<T> maybeT)
Create an AnyMSeq instance that wraps an MaybeTransformer
MaybeTSeq |
static <T> AnyMValue<T> |
fromMaybeTValue(MaybeTValue<T> maybeT)
Create an AnyMValue instance that wraps an MaybeTransformer
MaybeTValue |
static <T> AnyMValue<T> |
fromOptional(java.util.Optional<T> optional)
Create an AnyM instance that wraps an Optional
|
static AnyMValue<java.lang.Double> |
fromOptionalDouble(java.util.OptionalDouble optional)
Create an AnyM instance that wraps an OptionalDouble
|
static AnyMValue<java.lang.Integer> |
fromOptionalInt(java.util.OptionalInt optional)
Create an AnyM instance that wraps an OptionalInt
|
static AnyMValue<java.lang.Long> |
fromOptionalLong(java.util.OptionalLong optional)
Create an AnyM instance that wraps an OptionalLong
|
static <T> AnyMSeq<T> |
fromOptionalTSeq(OptionalTSeq<T> optionalT)
Create an AnyMSeq instance that wraps an OptionalTransformer
OptionalTSeq |
static <T> AnyMValue<T> |
fromOptionalTValue(OptionalTValue<T> optionalT)
Create an AnyMValue instance that wraps an OptionalTransformer
OptionalTValue |
static <T> AnyMSeq<T> |
fromPublisher(org.reactivestreams.Publisher<T> publisher)
Construct an AnyM that wraps a reactive-streams Publisher.
|
static AnyMSeq<java.lang.Integer> |
fromRange(int start,
int end)
Construct an AnyM instance that wraps a range from start (inclusive) to end (exclusive) provided
The AnyM will contain a SequenceM over the spefied range
|
static AnyMSeq<java.lang.Long> |
fromRangeLong(long start,
long end)
Construct an AnyM instance that wraps a range from start (inclusive) to end (exclusive) provided
The AnyM will contain a SequenceM over the spefied range
|
static <T> AnyMSeq<T> |
fromSet(java.util.Set<T> set)
Create an AnyM from a Set
This AnyM will convert the Set to a Stream under the covers, but will rematerialize the Stream as Set
if wrap() is called
|
static <T> AnyMSeq<T> |
fromSetT(SetT<T> setT)
Create an AnyMSeq instance that wraps an SetTransformer
SetTSeq |
static <T> AnyMSeq<T> |
fromStream(java.util.stream.Stream<T> stream)
Create an AnyM instance that wraps a Stream
|
static <T> AnyMSeq<T> |
fromStreamable(ToStream<T> streamable)
Wrap a Streamable inside an AnyM
|
static <T> AnyMSeq<T> |
fromStreamableT(StreamableT<T> streamT)
Create an AnyMSeq instance that wraps an StreamableTransformer
StreamableTSeq |
static <T> AnyMSeq<T> |
fromStreamT(StreamT<T> streamT)
Create an AnyMSeq instance that wraps an StreamTransformer
StreamTSeq |
static <T> AnyMValue<T> |
fromTry(Try<T,?> trySomething)
Create an AnyMValue instance that wraps a Try
|
static <T,X extends java.lang.Throwable> |
fromTryTSeq(TryTSeq<T,X> tryT)
Create an AnyMSeq instance that wraps an TryTransformer
TryTSeq |
static <T,X extends java.lang.Throwable> |
fromTryTValue(TryTValue<T,X> tryT)
Create an AnyMValue instance that wraps an TryTransformer
TryTValue |
static <T> AnyMValue<T> |
fromXor(Xor<?,T> xor)
Create an AnyMValue instance that wraps an Xor
|
static <ST,PT> AnyMSeq<PT> |
fromXorTSeq(XorTSeq<ST,PT> xorT)
Create an AnyMSeq instance that wraps an XorTransformer
XorTSeq |
static <ST,PT> AnyMValue<PT> |
fromXorTValue(XorTValue<ST,PT> xorT)
Create an AnyMValue instance that wraps an XorTransformer
CompletableFutureTValue |
static <U,R> java.util.function.Function<AnyM<U>,AnyM<R>> |
liftM(java.util.function.Function<? super U,? extends R> fn)
Lift a function so it accepts an AnyM and returns an AnyM (any monad)
|
static <U1,U2,R> java.util.function.BiFunction<AnyM<U1>,AnyM<U2>,AnyM<R>> |
liftM2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
Lift a function so it accepts an AnyM wrapped Monad and returns an AnyMwrapped Monad.
|
static <U1,U2,R> java.util.function.Function<AnyM<U1>,java.util.function.Function<AnyM<U2>,AnyM<R>>> |
liftM2(java.util.function.Function<U1,java.util.function.Function<U2,R>> fn)
Lift a Curried Function into Monadic form
|
static <U1,U2,U3,R> |
liftM3(java.util.function.Function<? super U1,java.util.function.Function<? super U2,java.util.function.Function<? super U3,? extends R>>> fn)
Lift a Curried Function into Monadic form
|
static <U1,U2,U3,R> |
liftM3(TriFunction<? super U1,? super U2,? super U3,? extends R> fn)
Lift a TriFunction into Monadic form.
|
static <U1,U2,U3,U4,R> |
liftM4(java.util.function.Function<? super U1,java.util.function.Function<? super U2,java.util.function.Function<? super U3,java.util.function.Function<? super U4,? extends R>>>> fn)
Lift a Curried Function into Monadic form
|
static <U1,U2,U3,U4,R> |
liftM4(QuadFunction<? super U1,? super U2,? super U3,? super U4,? extends R> fn)
Lift a QuadFunction into Monadic form.
|
static <U1,U2,U3,U4,U5,R> |
liftM5(java.util.function.Function<? super U1,java.util.function.Function<? super U2,java.util.function.Function<? super U3,java.util.function.Function<? super U4,java.util.function.Function<? super U5,? extends R>>>>> fn)
Lift a Curried Function
(5 levels a->b->c->d->e->fn.apply(a,b,c,d,e) ) into Monadic form |
static <U1,U2,U3,U4,U5,R> |
liftM5(QuintFunction<? super U1,? super U2,? super U3,? super U4,? super U5,? extends R> fn)
Lift a QuintFunction (5 parameters) into Monadic form
|
static <T> ListX<AnyMValue<T>> |
listFromCompletableFuture(java.lang.Iterable<java.util.concurrent.CompletableFuture<T>> anyM)
Take an iterable containing CompletableFutures and convert them into a List of AnyMs
e.g.
|
static <T> ListX<AnyMValue<T>> |
listFromEval(java.lang.Iterable<Eval<T>> anyM)
Take an iterable containing Evals and convert them into a List of AnyMs
e.g.
|
static <T> ListX<AnyMValue<T>> |
listFromFutureW(java.lang.Iterable<FutureW<T>> anyM)
Take an iterable containing FutureW and convert them into a List of AnyMs
e.g.
|
static <ST,T> ListX<AnyMValue<T>> |
listFromIor(java.lang.Iterable<Ior<ST,T>> anyM)
Take an iterable containing Iors and convert them into a List of AnyMs
e.g.
|
static <T> ListX<AnyMSeq<T>> |
listFromIterable(java.lang.Iterable<java.lang.Iterable<T>> anyM)
Take an iterable containing Streamables and convert them into a List of AnyMs
e.g.
|
static <T> ListX<AnyMSeq<T>> |
listFromIterator(java.lang.Iterable<java.util.Iterator<T>> anyM)
Take an iterable containing Streamables and convert them into a List of AnyMs
e.g.
|
static <T> ListX<AnyMValue<T>> |
listFromMaybe(java.lang.Iterable<Maybe<T>> anyM)
Take an iterable containing Maybes and convert them into a List of AnyMs
e.g.
|
static <T> ListX<AnyMValue<T>> |
listFromOptional(java.lang.Iterable<java.util.Optional<T>> anyM)
Take an iterable containing Optionals and convert them into a List of AnyMs
e.g.
|
static <T> ListX<AnyMSeq<T>> |
listFromStream(java.lang.Iterable<java.util.stream.Stream<T>> anyM)
Take an iterable containing Streams and convert them into a List of AnyMs
e.g.
|
static <T> ListX<AnyMSeq<T>> |
listFromStreamable(java.lang.Iterable<Streamable<T>> anyM)
Take an iterable containing Streamables and convert them into a List of AnyMs
e.g.
|
static <ST,T> ListX<AnyMValue<T>> |
listFromXor(java.lang.Iterable<Xor<ST,T>> anyM)
Take an iterable containing Xors and convert them into a List of AnyMs
e.g.
|
<R> AnyM<R> |
map(java.util.function.Function<? super T,? extends R> fn)
Perform a map operation on the wrapped monad instance e.g.
|
Xor<AnyMValue<T>,AnyMSeq<T>> |
matchable()
Allows structural matching on the value / seq nature of this AnyM.
|
static <T> AnyMSeq<T> |
ofConvertableSeq(java.lang.Object monad)
Take the supplied object and attempt to convert it to a supported Monad type
|
static <T> AnyMValue<T> |
ofConvertableValue(java.lang.Object monad)
Take the supplied object and attempt to convert it to a supported Monad type
|
static <T> AnyMValue<T> |
ofNullable(java.lang.Object nullable)
Generate an AnyM that wraps an Optional from the provided nullable object
|
static <T> AnyMSeq<T> |
ofSeq(java.lang.Object monad)
Create an AnyMSeq that wraps the untyped monad
|
static <T> AnyMValue<T> |
ofValue(java.lang.Object monad)
Create an AnyMValue that wraps the untyped monad
|
AnyM<T> |
peek(java.util.function.Consumer<? super T> c)
Perform a peek operation on the wrapped monad e.g.
|
AnyMSeq<T> |
reduceMSeq(Monoid<AnyMSeq<T>> reducer)
Perform a monadic reduction using a Monoid that combines AnyM types.
|
AnyMValue<T> |
reduceMValue(Monoid<AnyMValue<T>> reducer)
Perform a monadic reduction using a Monoid that combines AnyM types.
|
static <T1> AnyMValue<ListX<T1>> |
sequence(java.util.Collection<? extends AnyM<T1>> seq)
Convert a Collection of Monads to a Monad with a List
|
static <T> AnyM<java.util.stream.Stream<T>> |
sequence(java.util.stream.Stream<? extends AnyM<T>> source,
java.util.function.Supplier<? extends AnyM<java.util.stream.Stream<T>>> unitEmpty)
Convert a Stream of Monads to a Monad with a Stream
|
ReactiveSeq<T> |
stream() |
static <T> AnyMSeq<T> |
streamOf(T... streamData)
Create an AnyM wrapping a Stream of the supplied data
Identical to fromArray, exists as it may appear functionally more obvious to users than fromArray (which fits the convention)
|
<NT> ReactiveSeq<NT> |
toReactiveSeq(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends NT>> fn)
Sequence the contents of a Monad.
|
java.lang.String |
toString() |
static <T,R> AnyMValue<ListX<R>> |
traverse(java.util.Collection<? extends AnyM<T>> seq,
java.util.function.Function<? super T,? extends R> fn)
Convert a Collection of Monads to a Monad with a List applying the supplied function in the process
|
static <T,R> AnyM<java.util.stream.Stream<R>> |
traverse(java.util.stream.Stream<AnyM<T>> source,
java.util.function.Supplier<AnyM<java.util.stream.Stream<T>>> unitEmpty,
java.util.function.Function<? super T,? extends R> fn)
Convert a Stream of Monads to a Monad with a Stream applying the supplied function in the process
|
<T> AnyM<T> |
unit(T value)
Construct a new instanceof AnyM using the type of the underlying wrapped monad
|
<R> R |
unwrap()
Unwrap a wrapped value
|
endsWith, endsWithIterable, findAny, findFirst, firstValue, foldable, foldRight, foldRight, foldRight, foldRightMapToType, get, groupBy, join, join, join, mapReduce, 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
cast, patternMatch, trampoline
futureStream, getStreamable, isEmpty, iterator, jdkStream, reactiveSeq, reveresedJDKStream, reveresedStream
default <T> Unit<T> emptyUnit()
default boolean eqv(AnyM<T> t)
boolean eqv = AnyM.fromOptional(Optional.of(1)).eqv(AnyM.fromStream(Stream.of(1)));
//true
boolean eqv = AnyM.fromOptional(Optional.of(1)).eqv(AnyM.fromStream(Stream.of(1,2)));
//false
t
- AnyM to check for equivalence with this AnyMXor<AnyMValue<T>,AnyMSeq<T>> matchable()
AnyM<String> monad;
monad.matchable().visit(v->handleValue(v.get()),s->handleSequence(s.toList()));
<R> AnyM<R> flatMapFirst(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> fn)
fn
- FlatMaping function<R> AnyM<R> flatMapFirstPublisher(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> fn)
fn
- FlatMaping function<R,A> R collect(java.util.stream.Collector<? super T,A,R> collector)
AnyM<Integer> monad1 = AnyM.fromStream(Stream.of(1,2,3));
AnyM<Integer> monad2 = AnyM.fromOptional(Optional.of(1));
List<Integer> list1 = monad1.collect(Collectors.toList());
List<Integer> list2 = monad2.collect(Collectors.toList());
collector
- JDK collector to perform mutable reductionReactiveSeq<T> stream()
<NT> ReactiveSeq<NT> toReactiveSeq(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends NT>> fn)
Optional<List<Integer>> into Stream<Integer>
List<Integer> list = AnyM.fromOptional(Optional.of(Arrays.asList(1,2,3,4,5,6)))
.<Integer>toSequence(c->c.stream())
.collect(Collectors.toList());
assertThat(list,hasItems(1,2,3,4,5,6));
fn
- Function used to convert contents to Stream<R> R unwrap()
Unwrapable
unwrap
in interface Unwrapable
AnyM<T> filter(java.util.function.Predicate<? super T> p)
AnyM.fromOptional(Optional.of(10)).filter(i->i<10);
//AnyM[Optional.empty()]
AnyM.fromStream(Stream.of(5,10)).filter(i->i<10);
//AnyM[Stream[5]]
p
- Filtering predicate<R> AnyM<R> map(java.util.function.Function<? super T,? extends R> fn)
AnyM.fromIterable(Try.runWithCatch(this::loadData))
.map(data->transform(data))
AnyM.fromStream(Stream.of(1,2,3))
.map(i->i+2);
//AnyM[Stream[3,4,5]]
AnyM<T> peek(java.util.function.Consumer<? super T> c)
AnyM.fromCompletableFuture(CompletableFuture.supplyAsync(()->loadData())
.peek(System.out::println)
<R> AnyM<R> bind(java.util.function.Function<? super T,?> fn)
AnyM<List<Integer>> m = AnyM.fromStream(Stream.of(Arrays.asList(1,2,3),Arrays.asList(1,2,3)));
AnyM<Integer> intM = m.bind(Collection::stream);
fn
- flatMap function<T1> AnyM<T1> flatten()
AnyM<java.util.List<T>> aggregate(AnyM<T> next)
AnyM.fromStream(Stream.of(1,2,3,4))
.aggregate(anyM(Optional.of(5)))
AnyM[Stream[List[1,2,3,4,5]]
List<Integer> result = AnyM.fromStream(Stream.of(1,2,3,4))
.aggregate(anyM(Optional.of(5)))
.toSequence()
.flatten()
.toList();
assertThat(result,equalTo(Arrays.asList(1,2,3,4,5)));
next
- Monad to aggregate content with<T> AnyM<T> unit(T value)
AnyM<Integer> ints = AnyM.fromList(Arrays.asList(1,2,3);
AnyM<String> string = ints.unit("hello");
<T> AnyM<T> empty()
Any<Integer> ints = AnyM.fromStream(Stream.of(1,2,3));
AnyM<Integer> empty=ints.empty();
AnyMValue<T> reduceMValue(Monoid<AnyMValue<T>> reducer)
Monoid<AnyMValue<Integer>> optionalAdd = Monoid.of(AnyM.fromOptional(Optional.of(0)), (a,b)-> AnyM.fromOptional(Optional.of(a.get()+b.get())));
AnyM.fromStream(Stream.of(2,8,3,1)).reduceM(optionalAdd);
//AnyM[Optional(14)];
reducer
- An identity value (approx. a seed) and BiFunction with a single type to reduce this anyMAnyMSeq<T> reduceMSeq(Monoid<AnyMSeq<T>> reducer)
Monoid<AnyMSeq<Integer>> listAddFirst = Monoid.of(AnyM.fromList(Arrays.asList(0)), (a,b)-> AnyM.fromList(Arrays.asList(a.get(0)+b.get(0))));
AnyM.fromStream(Stream.of(2,8,3,1)).reduceM(listAddFirst);
//AnyM[Optional(14)];
reducer
- An identity value (approx. a seed) and BiFunction with a single type to reduce this anyMjava.lang.String toString()
toString
in class java.lang.Object
static AnyMSeq<java.lang.Integer> fromRange(int start, int end)
start
- Inclusive start of the rangeend
- Exclusive end of the rangestatic AnyMSeq<java.lang.Long> fromRangeLong(long start, long end)
start
- Inclusive start of the rangeend
- Exclusive end of the rangestatic <T> AnyMSeq<T> fromStreamable(ToStream<T> streamable)
streamable
- wrapstatic <T> AnyMSeq<T> fromList(java.util.List<T> list)
list
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromSet(java.util.Set<T> set)
set
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromArray(T... streamData)
streamData
- values to populate a Streamstatic <T> AnyMSeq<T> streamOf(T... streamData)
streamData
- values to populate a Streamstatic <T> AnyMSeq<T> fromPublisher(org.reactivestreams.Publisher<T> publisher)
AnyMSeq<Integer> flux = AnyM.fromPublisher(Flux.just(10,20,30));
//with cyclops-reactor
//AnyM[Flux[Integer]]]
//without cyclops-reactor
//AnyM[ReactiveSeq[Integer]]]
It is generally safer to define a Comprehender and use a non-converting call to generate the wrapped AnyM
(e.g. Reactor.Flux in cyclops-reactor for Pivotal Reactor Publishers)publisher
- Publisher to wrap inside an AnyMstatic <T> AnyMSeq<T> fromStream(java.util.stream.Stream<T> stream)
stream
- Stream to wrapstatic AnyMSeq<java.lang.Integer> fromIntStream(java.util.stream.IntStream stream)
stream
- IntStream to wrapstatic AnyMSeq<java.lang.Double> fromDoubleStream(java.util.stream.DoubleStream stream)
stream
- DoubleStream to wrapstatic AnyMSeq<java.lang.Long> fromLongStream(java.util.stream.LongStream stream)
stream
- LongStream to wrapstatic <T> AnyMValue<T> fromOptional(java.util.Optional<T> optional)
optional
- Optional to wrapstatic AnyMValue<java.lang.Double> fromOptionalDouble(java.util.OptionalDouble optional)
optional
- Optional to wrapstatic AnyMValue<java.lang.Long> fromOptionalLong(java.util.OptionalLong optional)
optional
- OptionalLong to wrapstatic AnyMValue<java.lang.Integer> fromOptionalInt(java.util.OptionalInt optional)
optional
- OptionalInt to wrapstatic <T> AnyMValue<T> fromCompletableFuture(java.util.concurrent.CompletableFuture<T> future)
future
- CompletableFuture to wrapstatic <T> AnyMValue<T> fromXor(Xor<?,T> xor)
xor
- Xor to wrap inside an AnyMstatic <T> AnyMValue<T> fromFeatureToggle(FeatureToggle<T> featureToggle)
featureToggle
- to wrap inside an AnyMstatic <T> AnyMValue<T> fromTry(Try<T,?> trySomething)
trySomething
- to wrap inside an AnyMstatic <T> AnyMValue<T> fromIor(Ior<?,T> ior)
ior
- to wrap inside an AnyMstatic <T> AnyMValue<T> fromEval(Eval<T> eval)
eval
- to wrap inside an AnyMstatic <T> AnyMValue<T> fromFutureW(FutureW<T> future)
future
- to wrap inside an AnyMstatic <T> AnyMValue<T> fromMaybe(Maybe<T> maybe)
Maybe
maybe
- to wrap inside an AnyMstatic <T> AnyMValue<T> fromEvalTValue(EvalTValue<T> evalT)
EvalTValue
evalT
- to wrap inside an AnyMstatic <T> AnyMValue<T> fromMaybeTValue(MaybeTValue<T> maybeT)
MaybeTValue
maybeT
- to wrap inside an AnyMstatic <T> AnyMValue<T> fromOptionalTValue(OptionalTValue<T> optionalT)
OptionalTValue
optionalT
- to wrap inside an AnyMstatic <T> AnyMValue<T> fromCompletableFutureTValue(CompletableFutureTValue<T> futureT)
CompletableFutureTValue
futureT
- to wrap inside an AnyMstatic <ST,PT> AnyMValue<PT> fromXorTValue(XorTValue<ST,PT> xorT)
CompletableFutureTValue
xorT
- to wrap inside an AnyMstatic <T,X extends java.lang.Throwable> AnyMValue<T> fromTryTValue(TryTValue<T,X> tryT)
TryTValue
tryT
- to wrap inside an AnyMstatic <ST,PT> AnyMSeq<PT> fromXorTSeq(XorTSeq<ST,PT> xorT)
XorTSeq
xorT
- to wrap inside an AnyMstatic <T,X extends java.lang.Throwable> AnyMSeq<T> fromTryTSeq(TryTSeq<T,X> tryT)
TryTSeq
tryT
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromEvalTSeq(EvalTSeq<T> evalT)
EvalTSeq
evalT
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromMaybeTSeq(MaybeTSeq<T> maybeT)
MaybeTSeq
maybeT
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromOptionalTSeq(OptionalTSeq<T> optionalT)
OptionalTSeq
optionalT
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromCompletableFutureTSeq(CompletableFutureTSeq<T> futureT)
CompletableFutureTSeq
futureT
- to wrap inside an AnyMstatic <T> AnyMValue<T> fromFutureWTValue(FutureWTValue<T> futureT)
FutureWTSeq
futureT
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromFutureWTSeq(FutureWTSeq<T> futureT)
FutureWTSeq
futureT
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromListT(ListT<T> listT)
ListTSeq
listT
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromStreamT(StreamT<T> streamT)
StreamTSeq
streamT
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromStreamableT(StreamableT<T> streamT)
StreamableTSeq
streamT
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromSetT(SetT<T> setT)
SetTSeq
setT
- to wrap inside an AnyMstatic <T> AnyMSeq<T> fromIterable(java.lang.Iterable<T> iterable)
iterable
- Iterable to wrapstatic <T> AnyMValue<T> fromIterableValue(java.lang.Iterable<T> iterable)
iterable
- To generate AnyMValue fromstatic <T> AnyMValue<T> ofConvertableValue(java.lang.Object monad)
monad
- Monad to convert to a supported type and wrap inside an AnyMValuestatic <T> AnyMSeq<T> ofConvertableSeq(java.lang.Object monad)
monad
- Monad to convert to a supported type and wrap inside an AnyMValuestatic <T> AnyMValue<T> ofValue(java.lang.Object monad)
monad
- to wrap inside an AnyMstatic <T> AnyMSeq<T> ofSeq(java.lang.Object monad)
monad
- to wrap inside an AnyMstatic <T> AnyMValue<T> ofNullable(java.lang.Object nullable)
nullable
- - Nullable object to generate an optional fromstatic <T> ListX<AnyMSeq<T>> listFromStreamable(java.lang.Iterable<Streamable<T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromStreamable(Arrays.asList(Streamable.of(1,2,3),Streamable.of(10,20,30));
//List[AnyM[Streamable[1,2,3],Streamable[10,20,30]]]
anyM
- Iterable containing Streamablesstatic <T> ListX<AnyMSeq<T>> listFromStream(java.lang.Iterable<java.util.stream.Stream<T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromStream(Arrays.asList(Stream.of(1,2,3),Stream.of(10,20,30));
//List[AnyM[Stream[1,2,3],Stream[10,20,30]]]
anyM
- Iterable containing Streamsstatic <T> ListX<AnyMValue<T>> listFromOptional(java.lang.Iterable<java.util.Optional<T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromStreamable(Arrays.asList(Optional.of(1),Optional.of(10));
//List[AnyM[Optional[1],Optional[10]]]
anyM
- Iterable containing Optionalstatic <T> ListX<AnyMValue<T>> listFromCompletableFuture(java.lang.Iterable<java.util.concurrent.CompletableFuture<T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromStreamable(Arrays.asList(CompletableFuture.completedFuture(1),CompletableFuture.supplyAsync(()->10));
//List[AnyM[CompletableFuture[1],CompleteableFuture[10]]]
anyM
- Iterable containing CompletableFuturestatic <T> ListX<AnyMSeq<T>> listFromIterable(java.lang.Iterable<java.lang.Iterable<T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromStreamable(Arrays.asList(Streamable.of(1,2,3),Streamable.of(10,20,30));
//List[AnyM[Streamable[1,2,3],Streamable[10,20,30]]]
anyM
- Iterable containing Streamablesstatic <ST,T> ListX<AnyMValue<T>> listFromXor(java.lang.Iterable<Xor<ST,T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromXor(Arrays.asList(Xor.primary(1),Xor.secondary(10));
//List[AnyM[Xor:primary[1],Xor:secondaary[10]]]
anyM
- Iterable containing Xorsstatic <ST,T> ListX<AnyMValue<T>> listFromIor(java.lang.Iterable<Ior<ST,T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromXor(Arrays.asList(Ior.primary(1),Ior.secondary(10));
//List[AnyM[Ior:primary[1],Ior:secondaary[10]]]
anyM
- Iterable containing Iorsstatic <T> ListX<AnyMValue<T>> listFromMaybe(java.lang.Iterable<Maybe<T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromXor(Arrays.asList(Maybe.just(1),Maybe.just(10));
//List[AnyM[Maybe[1],Maybe[10]]]
anyM
- Iterable containing Maybesstatic <T> ListX<AnyMValue<T>> listFromEval(java.lang.Iterable<Eval<T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromXor(Arrays.asList(Eval.now(1),Eval.now(10));
//List[AnyM[Eval[1],Eval[10]]]
anyM
- Iterable containing Maybesstatic <T> ListX<AnyMValue<T>> listFromFutureW(java.lang.Iterable<FutureW<T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromXor(Arrays.asList(FutureW.ofResult(1),FutureW.ofResult(10));
//List[AnyM[FutureW[1],FutureW[10]]]
anyM
- Iterable containing Maybesstatic <T> ListX<AnyMSeq<T>> listFromIterator(java.lang.Iterable<java.util.Iterator<T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromStreamable(Arrays.asList(Arrays.asList(1,2,3).iterator(),Arrays.asList(10,20,30)).iterator();
//List[AnyM[Stream[1,2,3],Stream[10,20,30]]]
anyM
- Iterable containing Iteratorsstatic <T1> AnyMValue<ListX<T1>> sequence(java.util.Collection<? extends AnyM<T1>> seq)
List<CompletableFuture<Integer>> futures = createFutures();
AnyM<List<Integer>> futureList = AnyMonads.sequence(AsAnyMList.anyMList(futures));
//where AnyM wraps CompletableFuture<List<Integer>>
seq
- Collection of monads to convertstatic <T,R> AnyMValue<ListX<R>> traverse(java.util.Collection<? extends AnyM<T>> seq, java.util.function.Function<? super T,? extends R> fn)
List<CompletableFuture<Integer>> futures = createFutures();
AnyM<List<String>> futureList = AnyMonads.traverse(AsAnyMList.anyMList(futures), (Integer i) -> "hello" +i);
seq
- Collection of Monadsfn
- Function to applystatic <T,R> AnyM<java.util.stream.Stream<R>> traverse(java.util.stream.Stream<AnyM<T>> source, java.util.function.Supplier<AnyM<java.util.stream.Stream<T>>> unitEmpty, java.util.function.Function<? super T,? extends R> fn)
source
- Stream to traverseunitEmpty
- Supplier to generate an AnyM with an Empty Streamfn
- Mapping functionstatic <T> AnyM<java.util.stream.Stream<T>> sequence(java.util.stream.Stream<? extends AnyM<T>> source, java.util.function.Supplier<? extends AnyM<java.util.stream.Stream<T>>> unitEmpty)
Supplier<AnyM<Stream<Integer>>> unitEmpty = ()->AnyM.fromOptional(Optional.of(Stream.<Integer>empty()));
AnyMValue<Integer> just = AnyM.fromOptional(Optional.of(10));
Stream<AnyM<Integer>> streamOfOptionals = ReactiveSeq.of(just,AnyM.fromOptional(Optional.of(1)));
AnyM<Stream<Integer>> optionalWithAStream =AnyM.sequence(streamOfOptionals, unitEmpty);
Optional<Stream<Integer>> optional = optionalWithAStream.unwrap();
source
- Stream of monads to sequenceunitEmpty
- Supplier to generate an AnyM with an Empty Streamstatic <U,R> java.util.function.Function<AnyM<U>,AnyM<R>> liftM(java.util.function.Function<? super U,? extends R> fn)
fn
- Function to Lift into monadic formstatic <U1,U2,R> java.util.function.BiFunction<AnyM<U1>,AnyM<U2>,AnyM<R>> liftM2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
BiFunction<AnyM<Integer>,AnyM<Integer>,AnyM<Integer>> add = Monads.liftM2(this::add);
Optional<Integer> result = add.apply(getBase(),getIncrease());
private Integer add(Integer a, Integer b){
return a+b;
}
The add method has no null handling, but we can lift the method to Monadic form, and use Optionals to automatically handle null / empty value cases.fn
- BiFunction to liftstatic <U1,U2,U3,R> TriFunction<AnyM<U1>,AnyM<U2>,AnyM<U3>,AnyM<R>> liftM3(TriFunction<? super U1,? super U2,? super U3,? extends R> fn)
TriFunction<AnyM<Double>,AnyM<Entity>,AnyM<String>,AnyM<Integer>> fn = liftM3(this::myMethod);
Now we can execute the Method with Streams, Optional, Futures, Try's etc to transparently inject iteration, null handling, async execution and / or error handlingfn
- Function to liftstatic <U1,U2,U3,U4,R> QuadFunction<AnyM<U1>,AnyM<U2>,AnyM<U3>,AnyM<U4>,AnyM<R>> liftM4(QuadFunction<? super U1,? super U2,? super U3,? super U4,? extends R> fn)
fn
- Quad funciton to liftstatic <U1,U2,U3,U4,U5,R> QuintFunction<AnyM<U1>,AnyM<U2>,AnyM<U3>,AnyM<U4>,AnyM<U5>,AnyM<R>> liftM5(QuintFunction<? super U1,? super U2,? super U3,? super U4,? super U5,? extends R> fn)
fn
- Function to liftstatic <U1,U2,R> java.util.function.Function<AnyM<U1>,java.util.function.Function<AnyM<U2>,AnyM<R>>> liftM2(java.util.function.Function<U1,java.util.function.Function<U2,R>> fn)
fn
- Function to liftstatic <U1,U2,U3,R> java.util.function.Function<AnyM<U1>,java.util.function.Function<AnyM<U2>,java.util.function.Function<AnyM<U3>,AnyM<R>>>> liftM3(java.util.function.Function<? super U1,java.util.function.Function<? super U2,java.util.function.Function<? super U3,? extends R>>> fn)
fn
- Function to liftstatic <U1,U2,U3,U4,R> java.util.function.Function<AnyM<U1>,java.util.function.Function<AnyM<U2>,java.util.function.Function<AnyM<U3>,java.util.function.Function<AnyM<U4>,AnyM<R>>>>> liftM4(java.util.function.Function<? super U1,java.util.function.Function<? super U2,java.util.function.Function<? super U3,java.util.function.Function<? super U4,? extends R>>>> fn)
fn
- Function to liftstatic <U1,U2,U3,U4,U5,R> java.util.function.Function<AnyM<U1>,java.util.function.Function<AnyM<U2>,java.util.function.Function<AnyM<U3>,java.util.function.Function<AnyM<U4>,java.util.function.Function<AnyM<U5>,AnyM<R>>>>>> liftM5(java.util.function.Function<? super U1,java.util.function.Function<? super U2,java.util.function.Function<? super U3,java.util.function.Function<? super U4,java.util.function.Function<? super U5,? extends R>>>>> fn)
(5 levels a->b->c->d->e->fn.apply(a,b,c,d,e) )
into Monadic formfn
- Function to lift