T
- type data wrapped by the underlying monadpublic interface AnyM<W extends WitnessType<W>,T> extends Unwrapable, To<AnyM<W,T>>, EmptyUnit<T>, Unit<T>, Folds<T>, Transformable<T>, ToStream<T>, Zippable<T>, org.reactivestreams.Publisher<T>
AnyMValue
and @see AnyMSeq
.
AnyMValue is used toNested represent Monads that wrap a single value such as Optional
, CompletableFuture
, Maybe
, Eval
, Xor
, Try
, Ior
, FeatureToggle
AnyMSeq is used toNested represent Monads that wrap an aggregation of values such as Stream
, FutureStream
, List
, Set
, Streamable
Use AnyM toNested create your monad wrapper.
AnyM.fromXXXX methods can create the appropriate AnyM type for a range of known monad types.
AnyMValue<optional,String> monad1 = AnyM.fromOptional(Optional.of("hello"));
AnyMSeq<stream,String> monad2 = AnyM.fromStream(Stream.of("hello","world"));
Wrapped monads can be unwrapped via the unwrap method, or converted toNested the desired type via toXXXX methodsModifier and Type | Interface and Description |
---|---|
static class |
AnyM.AnyMFactory |
Modifier and Type | Method and Description |
---|---|
FunctionalAdapter<W> |
adapter() |
default AnyM<W,java.util.List<T>> |
aggregate(AnyM<W,T> next)
Aggregate the contents of this Monad and the supplied Monad
|
static <W extends WitnessType<W>,T,R> |
ap(AnyM<W,java.util.function.Function<T,R>> fn)
Applicative 'ap' method toNested use fluently
|
static <W extends WitnessType<W>,T,T2,R> |
ap2(AnyM<W,java.util.function.Function<T,java.util.function.Function<T2,R>>> fn)
Applicative ap2 method toNested use fluently toNested apply toNested a curried function
|
default <R> AnyM<W,R> |
coflatMapA(java.util.function.Function<? super AnyM<W,T>,R> mapper) |
default <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 toNested Stream#collect
|
default <T> AnyM<W,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
|
default AnyM<W,T> |
filter(java.util.function.Predicate<? super T> fn)
Perform a filter operation on the wrapped monad instance e.g.
|
default <R> AnyM<W,R> |
flatMapA(java.util.function.Function<? super T,? extends AnyM<W,? extends R>> fn) |
<R> AnyM<W,R> |
flatMapI(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> fn) |
<R> AnyM<W,R> |
flatMapP(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> fn) |
<R> AnyM<W,R> |
flatMapS(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> fn) |
static <W extends WitnessType<W>,T1> |
flatten(AnyM<W,? extends AnyM<W,T1>> nested)
join / flatten one level of a nested hierarchy
|
static <W extends WitnessType<W>,T1> |
flattenI(AnyM<W,? extends java.lang.Iterable<T1>> nested) |
static <T> AnyMSeq<Witness.stream,T> |
fromArray(T... streamData)
Create an AnyM wrapping a Stream of the supplied data
|
static <T> AnyMSeq<Witness.bagX,T> |
fromBagX(BagX<T> set) |
static <W extends Witness.CollectionXWitness<W>,T> |
fromCollectionX(CollectionX<T> collection,
W witness) |
static <T> AnyMValue<Witness.completableFuture,T> |
fromCompletableFuture(java.util.concurrent.CompletableFuture<T> future)
Create an AnyM instance that wraps a CompletableFuture
|
static <T> AnyMSeq<Witness.deque,T> |
fromDeque(java.util.Deque<T> deque) |
static AnyMSeq<Witness.stream,java.lang.Double> |
fromDoubleStream(java.util.stream.DoubleStream stream)
Create an AnyM instance that wraps an DoubleStream
|
static <LT1,T> AnyMValue<Witness.either,T> |
fromEither(Either<LT1,T> xor)
Create an AnyMValue instance that wraps an Either3
|
static <LT1,LT2,T> |
fromEither3(Either3<LT1,LT2,T> xor)
Create an AnyMValue instance that wraps an Either3
|
static <LT1,LT2,LT3,T> |
fromEither4(Either4<LT1,LT2,LT3,T> xor)
Create an AnyMValue instance that wraps an Either4
|
static <LT1,LT2,LT3,LT4,T> |
fromEither5(Either5<LT1,LT2,LT3,LT4,T> xor)
Create an AnyMValue instance that wraps an Either4
|
static <T> AnyMValue<Witness.eval,T> |
fromEval(Eval<T> eval)
Create an AnyMValue instance that wraps an Eval
|
static <T> AnyMValue<Witness.future,T> |
fromFuture(Future<T> future)
Create an AnyMValue instance that wraps a Future
|
static <T> AnyMSeq<Witness.futureStream,T> |
fromFutureStream(FutureStream<T> stream)
Create an AnyM instance that wraps a FutureStream
|
static AnyMSeq<Witness.stream,java.lang.Integer> |
fromIntStream(java.util.stream.IntStream stream)
Create an AnyM instance that wraps an IntStream
|
static <T> AnyMValue<Witness.ior,T> |
fromIor(Ior<?,T> ior)
Create an AnyMValue instance that wraps an Ior
|
default <T> AnyM<W,T> |
fromIterable(java.lang.Iterable<T> t) |
static <T> AnyMSeq<Witness.linkedListX,T> |
fromLinkedListX(LinkedListX<T> list) |
static <T> AnyMSeq<Witness.list,T> |
fromList(java.util.List<T> list)
Create an AnyM from a List
|
static AnyMSeq<Witness.stream,java.lang.Long> |
fromLongStream(java.util.stream.LongStream stream)
Create an AnyM instance that wraps an LongStream
|
static <T> AnyMValue<Witness.maybe,T> |
fromMaybe(Maybe<T> maybe)
Create an AnyMValue instance that wraps a
Maybe |
static <W extends Witness.MonadicValueWitness<W>,T> |
fromMonadicValue(MonadicValue<T> eval,
W witness) |
static <T> AnyMValue<Witness.optional,T> |
fromOptional(java.util.Optional<T> opt)
Create an AnyM instance that wraps an Optional
|
static AnyMValue<Witness.optional,java.lang.Double> |
fromOptionalDouble(java.util.OptionalDouble optional)
Create an AnyM instance that wraps an OptionalDouble
|
static AnyMValue<Witness.optional,java.lang.Integer> |
fromOptionalInt(java.util.OptionalInt optional)
Create an AnyM instance that wraps an OptionalInt
|
static AnyMValue<Witness.optional,java.lang.Long> |
fromOptionalLong(java.util.OptionalLong optional)
Create an AnyM instance that wraps an OptionalLong
|
static <T> AnyMSeq<Witness.orderedSetX,T> |
fromOrderedSetX(OrderedSetX<T> set) |
static <T> AnyMSeq<Witness.persistentQueueX,T> |
fromPersistentQueueX(PersistentQueueX<T> set) |
static <T> AnyMSeq<Witness.persistentSetX,T> |
fromPersistentSetX(PersistentSetX<T> set) |
static <T> AnyMSeq<Witness.reactiveSeq,T> |
fromPublisher(org.reactivestreams.Publisher<T> publisher)
Construct an AnyM that wraps a reactive-streams Publisher.
|
static <T> AnyMSeq<Witness.queue,T> |
fromQueue(java.util.Queue<T> queue) |
static AnyMSeq<Witness.reactiveSeq,java.lang.Integer> |
fromRange(int start,
int end)
Construct an AnyM instance that wraps a range from skip (inclusive) toNested take (exclusive) provided
The AnyM will contain a SequenceM over the spefied range
|
static AnyMSeq<Witness.reactiveSeq,java.lang.Long> |
fromRangeLong(long start,
long end)
Construct an AnyM instance that wraps a range from skip (inclusive) toNested take (exclusive) provided
The AnyM will contain a SequenceM over the spefied range
|
static <T> AnyMSeq<Witness.set,T> |
fromSet(java.util.Set<T> set)
Create an AnyM from a Set
|
static <T> AnyMSeq<Witness.sortedSet,T> |
fromSortedSet(java.util.SortedSet<T> set) |
static <T> AnyMSeq<Witness.reactiveSeq,T> |
fromStream(ReactiveSeq<T> stream)
Create an AnyM instance that wraps a Stream
|
static <T> AnyMSeq<Witness.stream,T> |
fromStream(java.util.stream.Stream<T> stream)
Create an AnyM instance that wraps a Stream
|
static <W extends Witness.StreamWitness<W>,T> |
fromStream(java.util.stream.Stream<T> stream,
W witness) |
static <T> AnyMSeq<Witness.streamable,T> |
fromStreamable(ToStream<T> streamable)
Wrap a Streamable inside an AnyM
|
static <T> AnyMValue<Witness.tryType,T> |
fromTry(Try<T,?> trySomething)
Create an AnyMValue instance that wraps a Try
|
static <T> AnyMSeq<Witness.vectorX,T> |
fromVectorX(VectorX<T> list) |
static <T> AnyMValue<Witness.xor,T> |
fromXor(Xor<?,T> xor)
Create an AnyMValue instance that wraps an Xor
|
default java.util.Iterator<T> |
iterator() |
static <W extends WitnessType<W>,U,R> |
liftF(java.util.function.Function<? super U,? extends R> fn)
Lift a function so it accepts an AnyM and returns an AnyM (any monad)
AnyM view simplifies type related challenges.
|
static <W extends WitnessType<W>,U1,U2,R> |
liftF2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
Lift a function so it accepts a Monad and returns a Monad (simplex view of a wrapped Monad)
AnyM view simplifies type related challenges.
|
static <W extends WitnessType<W>,U1,U2,R> |
liftF2(java.util.function.Function<U1,java.util.function.Function<U2,R>> fn)
Lift a Curried Function into Monadic form
|
static <W extends WitnessType<W>,U1,U2,U3,R> |
liftF3(Fn3<? super U1,? super U2,? super U3,? extends R> fn)
Lift a TriFunction into Monadic form.
|
static <W extends WitnessType<W>,U1,U2,U3,R> |
liftF3(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 <W extends WitnessType<W>,U1,U2,U3,U4,R> |
liftF4(Fn4<? super U1,? super U2,? super U3,? super U4,? extends R> fn)
Lift a QuadFunction into Monadic form.
|
static <W extends WitnessType<W>,U1,U2,U3,U4,R> |
liftF4(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 <W extends WitnessType<W>,U1,U2,U3,U4,U5,R> |
liftF5(Fn5<? super U1,? super U2,? super U3,? super U4,? super U5,? extends R> fn)
Lift a jOOλ Function5 (5 parameters) into Monadic form
|
static <W extends WitnessType<W>,U1,U2,U3,U4,U5,R> |
liftF5(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 |
default FutureT<W,T> |
liftMFuture() |
default FutureT<W,T> |
liftMFuture(java.util.function.Function<? super T,? extends Future<T>> lift) |
default ListT<W,T> |
liftMList(java.util.function.Function<? super T,? extends IndexedSequenceX<T>> lift) |
default ListT<W,T> |
liftMListX() |
static <T> ListX<AnyMValue<Witness.completableFuture,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 <ST,T> ListX<AnyMValue<Witness.either,T>> |
listFromEither(java.lang.Iterable<Either<ST,T>> anyM)
Take an iterable containing Either3s and convert them into a List of AnyMs
e.g.
|
static <ST,LT2,T> ListX<AnyMValue<Witness.either3,T>> |
listFromEither3(java.lang.Iterable<Either3<ST,LT2,T>> anyM)
Take an iterable containing Either3s and convert them into a List of AnyMs
e.g.
|
static <ST,LT2,LT3,T> |
listFromEither4(java.lang.Iterable<Either4<ST,LT2,LT3,T>> anyM)
Take an iterable containing Either3s and convert them into a List of AnyMs
e.g.
|
static <ST,LT2,LT3,LT4,T> |
listFromEither5(java.lang.Iterable<Either5<ST,LT2,LT3,LT4,T>> anyM)
Take an iterable containing Either3s and convert them into a List of AnyMs
e.g.
|
static <T> ListX<AnyMValue<Witness.eval,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<Witness.future,T>> |
listFromFuture(java.lang.Iterable<Future<T>> anyM)
Take an iterable containing Future and convert them into a List of AnyMs
e.g.
|
static <ST,T> ListX<AnyMValue<Witness.ior,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<AnyMValue<Witness.maybe,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<Witness.optional,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<Witness.stream,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<Witness.streamable,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<Witness.xor,T>> |
listFromXor(java.lang.Iterable<Xor<ST,T>> anyM)
Take an iterable containing Xors and convert them into a List of AnyMs
e.g.
|
static <T> AnyMSeq<Witness.list,T> |
listOf(T... elements) |
default <R> AnyM<W,R> |
map(java.util.function.Function<? super T,? extends R> fn)
Transform this functor using the supplied transformation function
|
Xor<AnyMValue<W,T>,AnyMSeq<W,T>> |
matchable()
Allows structural matching on the value / seq nature of this AnyM.
|
static <W extends WitnessType<W>,T> |
narrow(AnyM<W,? extends T> anyM) |
default AnyM<W,AnyM<W,T>> |
nestA() |
static <T> AnyMValue<Witness.optional,T> |
ofNullable(java.lang.Object nullable)
Generate an AnyM that wraps an Optional from the provided nullable object
|
static <W extends WitnessType<W>,T> |
ofSeq(java.lang.Object monad,
W witness)
Create an AnyMSeq that wraps the untyped monad
|
static <W extends WitnessType<W>,T> |
ofValue(java.lang.Object monad,
FunctionalAdapter<?> adapter) |
static <W extends WitnessType<W>,T> |
ofValue(java.lang.Object monad,
W witness)
Create an AnyMValue that wraps the untyped monad
|
default AnyM<W,T> |
peek(java.util.function.Consumer<? super T> c)
Perform a peek operation on the wrapped monad e.g.
|
default ReactiveSeq<T> |
reactiveSeq() |
default <R> AnyM<W,R> |
retry(java.util.function.Function<? super T,? extends R> fn)
Retry a transformation if it fails.
|
default <R> AnyM<W,R> |
retry(java.util.function.Function<? super T,? extends R> fn,
int retries,
long delay,
java.util.concurrent.TimeUnit timeUnit)
Retry a transformation if it fails.
|
static <W extends WitnessType<W>,T1> |
sequence(java.util.Collection<? extends AnyM<W,T1>> seq,
W w)
Convert a Collection of Monads toNested a Monad with a List
|
static <W extends WitnessType<W>,T> |
sequence(java.util.stream.Stream<? extends AnyM<W,T>> stream,
W witness) |
default ReactiveSeq<T> |
stream() |
static <T> AnyMSeq<Witness.stream,T> |
streamOf(T... streamData)
Create an AnyM wrapping a Stream of the supplied data
Identical toNested fromArray, exists as it may appear functionally more obvious toNested users than fromArray (which fits the convention)
|
java.lang.String |
toString() |
static <W extends WitnessType<W>,T,R> |
traverse(java.util.Collection<? extends AnyM<W,T>> seq,
java.util.function.Function<? super T,? extends R> fn,
W w)
Convert a Collection of Monads toNested a Monad with a List applying the supplied function in the process
|
static <W extends WitnessType<W>,T,R> |
traverse(java.util.function.Function<T,R> fn,
java.util.stream.Stream<AnyM<W,T>> stream,
W witness) |
default <T> AnyM<W,T> |
unit(T t)
Construct a new instanceof AnyM using the type of the underlying wrapped monad
|
default <U> AnyMSeq<W,U> |
unitIterator(java.util.Iterator<U> U) |
default <S,U> AnyM<W,org.jooq.lambda.tuple.Tuple3<T,S,U>> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third)
zip 3 Streams into one
|
default <S,U,R> AnyM<W,R> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third,
Fn3<? super T,? super S,? super U,? extends R> fn3) |
default <T2,T3,T4> AnyM<W,org.jooq.lambda.tuple.Tuple4<T,T2,T3,T4>> |
zip4(java.lang.Iterable<? extends T2> second,
java.lang.Iterable<? extends T3> third,
java.lang.Iterable<? extends T4> fourth)
zip 4 Streams into 1
|
default <T2,T3,T4,R> |
zip4(java.lang.Iterable<? extends T2> second,
java.lang.Iterable<? extends T3> third,
java.lang.Iterable<? extends T4> fourth,
Fn4<? super T,? super T2,? super T3,? super T4,? extends R> fn) |
default <U> AnyM<W,org.jooq.lambda.tuple.Tuple2<T,U>> |
zipP(org.reactivestreams.Publisher<? extends U> other) |
default <R> AnyM<W,R> |
zipWith(java.lang.Iterable<java.util.function.Function<? super T,? extends R>> fn) |
default <R> AnyM<W,R> |
zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super T,? extends R>> fn) |
default <R> AnyM<W,R> |
zipWithS(java.util.stream.Stream<java.util.function.Function<? super T,? extends R>> fn) |
unwrap, unwrapIfInstance
endsWith, endsWithIterable, findAny, findFirst, firstValue, foldLeft, foldLeft, foldLeft, foldLeft, 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, xMatch
futureStream, getStreamable, isEmpty, jdkStream, reveresedJDKStream, reveresedStream
cast, trampoline
default ReactiveSeq<T> reactiveSeq()
reactiveSeq
in interface ConvertableToReactiveSeq<T>
reactiveSeq
in interface ToStream<T>
default <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(CyclopsCollectors.toList());
List<Integer> list2 = monad2.collect(CyclopsCollectors.toList());
collector
- JDK collector toNested perform mutable reductiondefault java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
<R> AnyM<W,R> flatMapI(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> fn)
<R> AnyM<W,R> flatMapP(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> fn)
<R> AnyM<W,R> flatMapS(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> fn)
default <R> AnyM<W,R> flatMapA(java.util.function.Function<? super T,? extends AnyM<W,? extends R>> fn)
default <R> AnyM<W,R> map(java.util.function.Function<? super T,? extends R> fn)
Transformable
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface Transformable<T>
fn
- Transformation functiondefault <R> AnyM<W,R> zipWith(java.lang.Iterable<java.util.function.Function<? super T,? extends R>> fn)
default <R> AnyM<W,R> zipWithS(java.util.stream.Stream<java.util.function.Function<? super T,? extends R>> fn)
default <R> AnyM<W,R> zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super T,? extends R>> fn)
default <R> AnyM<W,R> retry(java.util.function.Function<? super T,? extends R> fn)
Transformable
given(serviceMock.apply(anyInt())).willThrow(
new RuntimeException(new SocketException("First")),
new RuntimeException(new IOException("Second"))).willReturn(
"42");
String result = ReactiveSeq.of( 1, 2, 3)
.retry(serviceMock)
.firstValue();
//result = 42
retry
in interface Transformable<T>
fn
- Function toNested retry if failsdefault <U> AnyM<W,org.jooq.lambda.tuple.Tuple2<T,U>> zipP(org.reactivestreams.Publisher<? extends U> other)
default <R> AnyM<W,R> retry(java.util.function.Function<? super T,? extends R> fn, int retries, long delay, java.util.concurrent.TimeUnit timeUnit)
Transformable
given(serviceMock.apply(anyInt())).willThrow(
new RuntimeException(new SocketException("First")),
new RuntimeException(new IOException("Second"))).willReturn(
"42");
String result = ReactiveSeq.of( 1, 2, 3)
.retry(serviceMock, 7, 2, TimeUnit.SECONDS)
.firstValue();
//result = 42
retry
in interface Transformable<T>
fn
- Function toNested retry if failsretries
- Number of retriesdelay
- Delay in TimeUnitstimeUnit
- TimeUnit toNested use for delaydefault <S,U> AnyM<W,org.jooq.lambda.tuple.Tuple3<T,S,U>> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third)
Zippable
List<Tuple3<Integer, Integer, Character>> list = of(1, 2, 3, 4, 5, 6).zip3(of(100, 200, 300, 400), of('a', 'b', 'c')).collect(CyclopsCollectors.toList());
// [[1,100,'a'],[2,200,'b'],[3,300,'c']]
default <S,U,R> AnyM<W,R> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third, Fn3<? super T,? super S,? super U,? extends R> fn3)
default <T2,T3,T4> AnyM<W,org.jooq.lambda.tuple.Tuple4<T,T2,T3,T4>> zip4(java.lang.Iterable<? extends T2> second, java.lang.Iterable<? extends T3> third, java.lang.Iterable<? extends T4> fourth)
Zippable
List<Tuple4<Integer, Integer, Character, String>> list = of(1, 2, 3, 4, 5, 6).zip4(of(100, 200, 300, 400), of('a', 'b', 'c'), of("hello", "world"))
.collect(CyclopsCollectors.toList());
// [[1,100,'a',"hello"],[2,200,'b',"world"]]
default <T2,T3,T4,R> AnyM<W,R> zip4(java.lang.Iterable<? extends T2> second, java.lang.Iterable<? extends T3> third, java.lang.Iterable<? extends T4> fourth, Fn4<? super T,? super T2,? super T3,? super T4,? extends R> fn)
default <T> AnyM<W,T> unit(T t)
AnyM<Integer> ints = AnyM.fromList(Arrays.asList(1,2,3);
AnyM<String> string = ints.unit("hello");
static <W extends WitnessType<W>,T,R> java.util.function.Function<AnyM<W,T>,AnyM<W,R>> ap(AnyM<W,java.util.function.Function<T,R>> fn)
AnyM<optional,Function<Integer,Integer>> add = AnyM.fromNullable(this::add2);
add.toNested(AnyM::ap)
.apply(AnyM.ofNullable(10));
//AnyM[12] //add 2
fn
- Function inside an Applicativestatic <W extends WitnessType<W>,T,T2,R> java.util.function.BiFunction<AnyM<W,T>,AnyM<W,T2>,AnyM<W,R>> ap2(AnyM<W,java.util.function.Function<T,java.util.function.Function<T2,R>>> fn)
AnyM<optional,Function<Integer,Function<Integer,Integer>>> add = AnyM.fromNullable(Curry.curry2(this::add));
add.toNested(AnyM::ap2)
.apply(AnyM.ofNullable(10),AnyM.ofNullable(20));
//AnyM[30] //add together
fn
- Curried function inside an Applicativedefault AnyM<W,T> filter(java.util.function.Predicate<? super T> fn)
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]]
fn
- Filtering predicatedefault <R> AnyM<W,R> coflatMapA(java.util.function.Function<? super AnyM<W,T>,R> mapper)
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 toNested check for equivalence with this AnyMXor<AnyMValue<W,T>,AnyMSeq<W,T>> matchable()
AnyM<String> monad;
monad.matchable().visit(v->handleValue(v.get()),s->handleSequence(s.toList()));
default ReactiveSeq<T> stream()
default AnyM<W,T> peek(java.util.function.Consumer<? super T> c)
AnyM.fromCompletableFuture(CompletableFuture.supplyAsync(()->loadData())
.peek(System.out::println)
peek
in interface Transformable<T>
c
- Consumer toNested accept current datastatic <W extends WitnessType<W>,T1> AnyM<W,T1> flatten(AnyM<W,? extends AnyM<W,T1>> nested)
static <W extends WitnessType<W>,T1> AnyM<W,T1> flattenI(AnyM<W,? extends java.lang.Iterable<T1>> nested)
default AnyM<W,java.util.List<T>> aggregate(AnyM<W,T> next)
AnyM.fromStream(Stream.of(1,2,3,4))
.aggregate(fromEither5(Optional.of(5)))
AnyM[Stream[List[1,2,3,4,5]]
List<Integer> result = AnyM.fromStream(Stream.of(1,2,3,4))
.aggregate(fromEither5(Optional.of(5)))
.toSequence()
.flatten()
.toList();
assertThat(result,equalTo(Arrays.asList(1,2,3,4,5)));
next
- Monad toNested aggregate content withdefault <T> AnyM<W,T> empty()
Any<Integer> ints = AnyM.fromStream(Stream.of(1,2,3));
AnyM<Integer> empty=ints.empty();
java.lang.String toString()
toString
in class java.lang.Object
static AnyMSeq<Witness.reactiveSeq,java.lang.Integer> fromRange(int start, int end)
start
- Inclusive skip of the rangeend
- Exclusive take of the rangestatic AnyMSeq<Witness.reactiveSeq,java.lang.Long> fromRangeLong(long start, long end)
start
- Inclusive skip of the rangeend
- Exclusive take of the rangestatic <T> AnyMSeq<Witness.streamable,T> fromStreamable(ToStream<T> streamable)
streamable
- wrapstatic <T> AnyMSeq<Witness.list,T> fromList(java.util.List<T> list)
list
- toNested wrap inside an AnyMstatic <W extends Witness.CollectionXWitness<W>,T> AnyMSeq<W,T> fromCollectionX(CollectionX<T> collection, W witness)
static <T> AnyMSeq<Witness.set,T> fromSet(java.util.Set<T> set)
set
- toNested wrap inside an AnyMstatic <T> AnyMSeq<Witness.queue,T> fromQueue(java.util.Queue<T> queue)
static <T> AnyMSeq<Witness.deque,T> fromDeque(java.util.Deque<T> deque)
static <T> AnyMSeq<Witness.sortedSet,T> fromSortedSet(java.util.SortedSet<T> set)
static <T> AnyMSeq<Witness.linkedListX,T> fromLinkedListX(LinkedListX<T> list)
static <T> AnyMSeq<Witness.vectorX,T> fromVectorX(VectorX<T> list)
static <T> AnyMSeq<Witness.persistentSetX,T> fromPersistentSetX(PersistentSetX<T> set)
static <T> AnyMSeq<Witness.persistentQueueX,T> fromPersistentQueueX(PersistentQueueX<T> set)
static <T> AnyMSeq<Witness.orderedSetX,T> fromOrderedSetX(OrderedSetX<T> set)
static <T> AnyMSeq<Witness.bagX,T> fromBagX(BagX<T> set)
static <T> AnyMSeq<Witness.stream,T> fromArray(T... streamData)
streamData
- values toNested populate a Streamstatic <T> AnyMSeq<Witness.stream,T> streamOf(T... streamData)
streamData
- values toNested populate a Streamstatic <T> AnyMSeq<Witness.list,T> listOf(T... elements)
static <T> AnyMSeq<Witness.reactiveSeq,T> fromPublisher(org.reactivestreams.Publisher<T> publisher)
AnyMSeq<Integer> flux = AnyM.fromPublisher(Flux.just(10,20,30));
//with cyclops2-reactor
//AnyM[Flux[Integer]]]
//without cyclops2-reactor
//AnyM[ReactiveSeq[Integer]]]
It is generally safer toNested define a Comprehender and use a non-converting call toNested generate the wrapped AnyM
(e.g. Reactor.Flux in cyclops2-reactor for Pivotal Reactor Publishers)publisher
- Publisher toNested wrap inside an AnyMstatic <T> AnyMSeq<Witness.reactiveSeq,T> fromStream(ReactiveSeq<T> stream)
stream
- Stream toNested wrapstatic <T> AnyMSeq<Witness.futureStream,T> fromFutureStream(FutureStream<T> stream)
stream
- FutureStream toNested wrapstatic <W extends Witness.StreamWitness<W>,T> AnyMSeq<W,T> fromStream(java.util.stream.Stream<T> stream, W witness)
static <T> AnyMSeq<Witness.stream,T> fromStream(java.util.stream.Stream<T> stream)
stream
- Stream toNested wrapstatic AnyMSeq<Witness.stream,java.lang.Integer> fromIntStream(java.util.stream.IntStream stream)
stream
- IntStream toNested wrapstatic AnyMSeq<Witness.stream,java.lang.Double> fromDoubleStream(java.util.stream.DoubleStream stream)
stream
- DoubleStream toNested wrapstatic AnyMSeq<Witness.stream,java.lang.Long> fromLongStream(java.util.stream.LongStream stream)
stream
- LongStream toNested wrapstatic <T> AnyMValue<Witness.optional,T> fromOptional(java.util.Optional<T> opt)
opt
- Optional toNested wrapstatic AnyMValue<Witness.optional,java.lang.Double> fromOptionalDouble(java.util.OptionalDouble optional)
optional
- Optional toNested wrapstatic AnyMValue<Witness.optional,java.lang.Long> fromOptionalLong(java.util.OptionalLong optional)
optional
- OptionalLong toNested wrapstatic AnyMValue<Witness.optional,java.lang.Integer> fromOptionalInt(java.util.OptionalInt optional)
optional
- OptionalInt toNested wrapstatic <T> AnyMValue<Witness.completableFuture,T> fromCompletableFuture(java.util.concurrent.CompletableFuture<T> future)
future
- CompletableFuture toNested wrapstatic <T> AnyMValue<Witness.xor,T> fromXor(Xor<?,T> xor)
xor
- Xor toNested wrap inside an AnyMstatic <LT1,T> AnyMValue<Witness.either,T> fromEither(Either<LT1,T> xor)
xor
- Xor toNested wrap inside an AnyMstatic <LT1,LT2,T> AnyMValue<Witness.either3,T> fromEither3(Either3<LT1,LT2,T> xor)
xor
- Xor toNested wrap inside an AnyMstatic <LT1,LT2,LT3,T> AnyMValue<Witness.either4,T> fromEither4(Either4<LT1,LT2,LT3,T> xor)
xor
- Either4 toNested wrap inside an AnyMstatic <LT1,LT2,LT3,LT4,T> AnyMValue<Witness.either5,T> fromEither5(Either5<LT1,LT2,LT3,LT4,T> xor)
xor
- Either4 toNested wrap inside an AnyMstatic <T> AnyMValue<Witness.tryType,T> fromTry(Try<T,?> trySomething)
trySomething
- toNested wrap inside an AnyMstatic <T> AnyMValue<Witness.ior,T> fromIor(Ior<?,T> ior)
ior
- toNested wrap inside an AnyMstatic <T> AnyMValue<Witness.eval,T> fromEval(Eval<T> eval)
eval
- toNested wrap inside an AnyMstatic <W extends Witness.MonadicValueWitness<W>,T> AnyMValue<W,T> fromMonadicValue(MonadicValue<T> eval, W witness)
static <T> AnyMValue<Witness.future,T> fromFuture(Future<T> future)
future
- toNested wrap inside an AnyMstatic <T> AnyMValue<Witness.maybe,T> fromMaybe(Maybe<T> maybe)
Maybe
maybe
- toNested wrap inside an AnyMstatic <W extends WitnessType<W>,T> AnyMValue<W,T> ofValue(java.lang.Object monad, W witness)
monad
- toNested wrap inside an AnyMstatic <W extends WitnessType<W>,T> AnyMValue<W,T> ofValue(java.lang.Object monad, FunctionalAdapter<?> adapter)
static <W extends WitnessType<W>,T> AnyMSeq<W,T> ofSeq(java.lang.Object monad, W witness)
monad
- toNested wrap inside an AnyMstatic <T> AnyMValue<Witness.optional,T> ofNullable(java.lang.Object nullable)
nullable
- - Nullable object toNested generate an optional fromstatic <T> ListX<AnyMSeq<Witness.streamable,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 <ST,LT2,LT3,LT4,T> ListX<AnyMValue<Witness.either5,T>> listFromEither5(java.lang.Iterable<Either5<ST,LT2,LT3,LT4,T>> anyM)
List<AnyM<Integer>> anyMs = anyMList(Arrays.asList(Either4.right(1),Either4.left(10));
//List[AnyM[Either4:right[1],Either4:left[10]]]
anyM
- Iterable containing Eithersstatic <ST,LT2,LT3,T> ListX<AnyMValue<Witness.either4,T>> listFromEither4(java.lang.Iterable<Either4<ST,LT2,LT3,T>> anyM)
List<AnyM<Integer>> anyMs = anyMList(Arrays.asList(Either4.right(1),Either4.left(10));
//List[AnyM[Either4:right[1],Either4:left[10]]]
anyM
- Iterable containing Eithersstatic <ST,LT2,T> ListX<AnyMValue<Witness.either3,T>> listFromEither3(java.lang.Iterable<Either3<ST,LT2,T>> anyM)
List<AnyM<Integer>> anyMs = listFromEither3(Arrays.asList(Either3.right(1),Either3.left(10));
//List[AnyM[Either3:right[1],Either3:left[10]]]
anyM
- Iterable containing Eithersstatic <ST,T> ListX<AnyMValue<Witness.either,T>> listFromEither(java.lang.Iterable<Either<ST,T>> anyM)
List<AnyM<Integer>> anyMs = anyMList(Arrays.asList(Either.right(1),Either.left(10));
//List[AnyM[Either.right[1],Either:left[10]]]
anyM
- Iterable containing Eithersstatic <T> ListX<AnyMSeq<Witness.stream,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<Witness.optional,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<Witness.completableFuture,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 <ST,T> ListX<AnyMValue<Witness.xor,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<Witness.ior,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<Witness.maybe,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<Witness.eval,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<Witness.future,T>> listFromFuture(java.lang.Iterable<Future<T>> anyM)
List<AnyM<Integer>> anyMs = AnyM.listFromXor(Arrays.asList(Future.ofResult(1),Future.ofResult(10));
//List[AnyM[Future[1],Future[10]]]
anyM
- Iterable containing Maybesstatic <W extends WitnessType<W>,T1> AnyM<W,ListX<T1>> sequence(java.util.Collection<? extends AnyM<W,T1>> seq, W w)
List<CompletableFuture<Integer>> futures = createFutures();
AnyM<List<Integer>> futureList = AnyMonads.sequence(AsAnyMList.anyMList(futures));
//where AnyM wraps CompletableFuture<List<Integer>>
seq
- Collection of monads toNested convertstatic <W extends WitnessType<W>,T,R> AnyM<W,ListX<R>> traverse(java.util.Collection<? extends AnyM<W,T>> seq, java.util.function.Function<? super T,? extends R> fn, W w)
List<CompletableFuture<Integer>> futures = createFutures();
AnyM<List<String>> futureList = AnyMonads.traverse(AsAnyMList.anyMList(futures), (Integer i) -> "hello" +i);
seq
- Collection of Monadsfn
- Function toNested applystatic <W extends WitnessType<W>,T> AnyM<W,java.util.stream.Stream<T>> sequence(java.util.stream.Stream<? extends AnyM<W,T>> stream, W witness)
static <W extends WitnessType<W>,T,R> AnyM<W,java.util.stream.Stream<R>> traverse(java.util.function.Function<T,R> fn, java.util.stream.Stream<AnyM<W,T>> stream, W witness)
FunctionalAdapter<W> adapter()
static <W extends WitnessType<W>,T> AnyM<W,T> narrow(AnyM<W,? extends T> anyM)
static <W extends WitnessType<W>,U,R> AnyMFn1<W,U,R> liftF(java.util.function.Function<? super U,? extends R> fn)
fn
- static <W extends WitnessType<W>,U1,U2,R> AnyMFn2<W,U1,U2,R> liftF2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
BiFunction<AnyM<Integer>,AnyM<Integer>,AnyM<Integer>> add = Monads.liftF2(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 toNested Monadic form, and use Optionals toNested automatically handle null / empty value cases.fn
- BiFunction toNested liftstatic <W extends WitnessType<W>,U1,U2,U3,R> Fn3<AnyM<W,U1>,AnyM<W,U2>,AnyM<W,U3>,AnyM<W,R>> liftF3(Fn3<? super U1,? super U2,? super U3,? extends R> fn)
TriFunction<AnyM<Double>,AnyM<Entity>,AnyM<W,String>,AnyM<Integer>> fn = liftF3(this::myMethod);
Now we can execute the Method with Streams, Optional, Futures, Try's etc toNested transparently inject iteration, null handling, async execution and / or error handlingfn
- Function toNested liftstatic <W extends WitnessType<W>,U1,U2,U3,U4,R> Fn4<AnyM<W,U1>,AnyM<W,U2>,AnyM<W,U3>,AnyM<W,U4>,AnyM<W,R>> liftF4(Fn4<? super U1,? super U2,? super U3,? super U4,? extends R> fn)
fn
- Quad funciton toNested liftstatic <W extends WitnessType<W>,U1,U2,U3,U4,U5,R> Fn5<AnyM<W,U1>,AnyM<W,U2>,AnyM<W,U3>,AnyM<W,U4>,AnyM<W,U5>,AnyM<W,R>> liftF5(Fn5<? super U1,? super U2,? super U3,? super U4,? super U5,? extends R> fn)
fn
- Function toNested liftstatic <W extends WitnessType<W>,U1,U2,R> java.util.function.Function<AnyM<W,U1>,java.util.function.Function<AnyM<W,U2>,AnyM<W,R>>> liftF2(java.util.function.Function<U1,java.util.function.Function<U2,R>> fn)
fn
- Function toNested liftstatic <W extends WitnessType<W>,U1,U2,U3,R> java.util.function.Function<AnyM<W,U1>,java.util.function.Function<AnyM<W,U2>,java.util.function.Function<AnyM<W,U3>,AnyM<W,R>>>> liftF3(java.util.function.Function<? super U1,java.util.function.Function<? super U2,java.util.function.Function<? super U3,? extends R>>> fn)
fn
- Function toNested liftstatic <W extends WitnessType<W>,U1,U2,U3,U4,R> java.util.function.Function<AnyM<W,U1>,java.util.function.Function<AnyM<W,U2>,java.util.function.Function<AnyM<W,U3>,java.util.function.Function<AnyM<W,U4>,AnyM<W,R>>>>> liftF4(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 toNested liftstatic <W extends WitnessType<W>,U1,U2,U3,U4,U5,R> java.util.function.Function<AnyM<W,U1>,java.util.function.Function<AnyM<W,U2>,java.util.function.Function<AnyM<W,U3>,java.util.function.Function<AnyM<W,U4>,java.util.function.Function<AnyM<W,U5>,AnyM<W,R>>>>>> liftF5(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 toNested liftdefault FutureT<W,T> liftMFuture(java.util.function.Function<? super T,? extends Future<T>> lift)
default ListT<W,T> liftMList(java.util.function.Function<? super T,? extends IndexedSequenceX<T>> lift)