T
- Data types of elements managed by wrapped scalar Monad.public interface AnyMValue2<W extends WitnessType<W>,T2,T> extends AnyM2<W,T2,T>, AnyMValue<W,T>, Value<T>, Filters<T>, MonadicValue<T>
AnyM.AnyMFactory
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Fn0.FunctionalOperations<R>, Fn0.Instances, Fn0.SupplierKind<R>
Modifier and Type | Method and Description |
---|---|
default AnyMValue<W,java.util.List<T>> |
aggregate(AnyM<W,T> next)
Aggregate the contents of this Monad and the supplied Monad
|
default int |
arity() |
default <U> AnyMValue2<W,T2,U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a reactiveStream to a given type, possibly throwing a
ClassCastException . |
default <R> AnyMValue2<W,T2,R> |
coflatMap(java.util.function.Function<? super MonadicValue<T>,R> mapper)
Perform a coflatMap operation.
|
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 to Stream#collect
|
default <T2,R> AnyMValue2<W,T2,R> |
combine(Value<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Lazily combine this ApplicativeFunctor with the supplied value via the supplied BiFunction
Example
|
default AnyMValue2<W,T2,T> |
combineEager(Monoid<T> monoid,
AnyMValue<W,? extends T> v2) |
default AnyMValue2<W,T2,T> |
combineEager(Monoid<T> monoid,
MonadicValue<? extends T> v2)
Eagerly combine two MonadicValues using the supplied monoid (@see ApplicativeFunctor for type appropraite i.e.
|
default <T> AnyMValue2<W,T2,T> |
empty()
Construct an AnyM wrapping a new zero instance of the wrapped type
e.g.
|
default <T> AnyMValue2<W,T2,T> |
emptyUnit() |
default boolean |
eqv(AnyMValue2<?,T2,T> t)
Equivalence test, returns true if this Monad is equivalent to the supplied monad
e.g.
|
default AnyMValue2<W,T2,T> |
filter(java.util.function.Predicate<? super T> p)
Perform a filter operation on the wrapped monad instance e.g.
|
default AnyMValue2<W,T2,T> |
filterNot(java.util.function.Predicate<? super T> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
default <R> AnyMValue2<W,T2,R> |
flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> fn)
A flattening transformation operation (@see
Optional.flatMap(Function) |
default <R> AnyMValue2<W,T2,R> |
flatMapA(java.util.function.Function<? super T,? extends AnyM<W,? extends R>> fn) |
default <R> AnyMValue2<W,T2,R> |
flatMapI(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> fn)
A flattening transformation operation that takes the first value from the returned Iterable.
|
default <R> AnyMValue2<W,T2,R> |
flatMapP(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> fn)
A flattening transformation operation that takes the first value from the returned Publisher.
|
default <R> AnyMValue2<W,T2,R> |
flatMapS(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> fn) |
default T |
foldLeft(T identity,
java.util.function.BinaryOperator<T> accumulator) |
default <R1,R> AnyMValue2<W,T2,R> |
forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied MonadicValue
|
default <R1,R> AnyMValue2<W,T2,R> |
forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,java.lang.Boolean> filterFunction,
java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied reactiveStream
|
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
Perform a three level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super T,? super R1,? super R2,java.lang.Boolean> filterFunction,
Fn3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
Perform a three level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Fn4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
Perform a four level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Fn4<? super T,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction,
Fn4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
Perform a four level nested internal iteration over this MonadicValue and the
supplied MonadicValues
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c<100,
(a,b,c,d)->a+b+c+d);
//Maybe.none
|
default T |
get() |
default boolean |
isPresent() |
default java.util.Iterator<T> |
iterator() |
default <R> AnyMValue2<W,T2,R> |
map(java.util.function.Function<? super T,? extends R> fn)
Transform this functor using the supplied transformation function
|
default Xor<AnyMValue<W,T>,AnyMSeq<W,T>> |
matchable()
Allows structural matching on the value / seq nature of this AnyM.
|
default java.lang.String |
mkString()
Returns the class name and the name of the subclass, if there is any value, the value is showed between square brackets.
|
default AnyMValue<W,MonadicValue<T>> |
nest()
cojoin pattern.
|
default AnyMValue2<W,T2,T> |
notNull()
Filter elements retaining only values which are not null
|
default <U> AnyMValue2<W,T2,U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a reactiveStream that are of a given type.
|
default AnyMValue2<W,T2,T> |
peek(java.util.function.Consumer<? super T> c)
Perform a peek operation on the wrapped monad e.g.
|
default <R> AnyMValue2<W,T2,R> |
retry(java.util.function.Function<? super T,? extends R> fn)
Retry a transformation if it fails.
|
default <R> AnyMValue2<W,T2,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.
|
default ReactiveSeq<T> |
stream() |
default <R> AnyMValue2<W,T2,R> |
trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
default <T> AnyMValue2<W,T2,T> |
unit(T value)
Construct a new instanceof AnyM using the type of the underlying wrapped monad
|
default AnyMValue2<W,T2,T> |
zip(java.util.function.BinaryOperator<Zippable<T>> combiner,
Zippable<T> app)
Combine two applicatives together using the provided BinaryOperator (Semigroup, Monoid and Reducer all
extend BinaryOperator - checkout SemigroupK and Monoids for a large number of canned combinations).
|
default <T2,R> AnyMValue2<W,T2,R> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Iterable using the supplied combining function
|
default <S,U> AnyMValue2<W,T2,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> AnyMValue2<W,T2,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> AnyMValue2<W,T2,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 <T2,R> AnyMValue2<W,T2,R> |
zipP(org.reactivestreams.Publisher<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Publisher, using the supplied combining function
|
default <U> AnyMValue2<W,T2,org.jooq.lambda.tuple.Tuple2<T,U>> |
zipP(org.reactivestreams.Publisher<? extends U> other) |
default <R> AnyMValue2<W,T2,R> |
zipWith(java.lang.Iterable<java.util.function.Function<? super T,? extends R>> fn) |
default <R> AnyMValue2<W,T2,R> |
zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super T,? extends R>> fn) |
default <R> AnyMValue2<W,T2,R> |
zipWithS(java.util.stream.Stream<java.util.function.Function<? super T,? extends R>> fn) |
adapter, aggregate, ap, ap2, coflatMapA, eqv, flatten, flattenI, fromIterable, liftF, liftF2, liftF2, liftF3, liftF3, liftF4, liftF4, liftF5, liftF5, liftMFuture, liftMFuture, liftMList, liftMListX, narrow, nestA, reactiveSeq, sequence, sequence, to2, toString, traverse, traverse, unitIterator
always, always, ap, ap2, completableFutureOf, eqv, failure, flatten, flattenI, fromArray, fromBagX, fromCollectionX, fromCompletableFuture, fromDeque, fromDoubleStream, fromEither, fromEither3, fromEither4, fromEither5, fromEval, fromFuture, fromFutureStream, fromIdentity, fromIntStream, fromIor, fromLinkedListX, fromList, fromLongStream, fromMaybe, fromMonadicValue, fromOptional, fromOptionalDouble, fromOptionalInt, fromOptionalLong, fromOrderedSetX, fromPersistentQueueX, fromPersistentSetX, fromPublisher, fromQueue, fromSet, fromSortedSet, fromStream, fromStream, fromStream, fromStreamable, fromTry, fromVectorX, fromXor, futureOf, generate, identity, just, later, left, liftF3, liftF4, liftF5, listFromCompletableFuture, listFromEither, listFromEither3, listFromEither4, listFromEither5, listFromEval, listFromFuture, listFromIor, listFromMaybe, listFromOptional, listFromStream, listFromStreamable, listFromXor, listOf, maybeNullable, narrow, none, ofNullable, ofSeq, ofValue, ofValue, ofValue2, ofValue2, primary, rangeLongOf, rangeOf, right, secondary, sequence, sequence, streamOf, success, success, traverse, traverse, zip, zipS, zipS
apply, generate, iterate, newSubscriber, of, subscribe, test, toEither, toEval, toEvalAlways, toEvalLater, toEvalNow, toIor, toLeft, toMaybe, toMaybeEager, toRight, toTry, toTry, toTry, toXor, toXor
endsWith, endsWithIterable, findAny, findFirst, firstValue, 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, singleUnsafe, startsWith, startsWithIterable, takeOne, xMatch
fromSupplier, orElse, orElseGet, orElseThrow, toCompletableFuture, toCompletableFutureAsync, toFuture, toFutureAsync, toOptional, toStream, visit
default <R,A> R collect(java.util.stream.Collector<? super T,A,R> collector)
AnyM2
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());
collect
in interface AnyM<W extends WitnessType<W>,T>
collect
in interface AnyM2<W extends WitnessType<W>,T2,T>
collect
in interface AnyMValue<W extends WitnessType<W>,T>
collect
in interface Convertable<T>
collector
- JDK collector to perform mutable reductiondefault boolean eqv(AnyMValue2<?,T2,T> t)
{code Optional.of(1) and CompletableFuture.completedFuture(1) are equivalent }
t
- Monad to compare todefault AnyMValue2<W,T2,T> zip(java.util.function.BinaryOperator<Zippable<T>> combiner, Zippable<T> app)
Zippable
zip
in interface AnyM<W extends WitnessType<W>,T>
zip
in interface AnyMValue<W extends WitnessType<W>,T>
zip
in interface Zippable<T>
Semigroup
,
Semigroups
,
Monoid
,
To lift any Semigroup (or monoid) up to handling Applicatives use the combineApplicatives operator in SemigroupK
{@see com.aol.cyclops2.SemigroupK#combineApplicatives(BiFunction) } or Monoids
{ {@see com.aol.cyclops2.Monoids#combineApplicatives(java.util.function.Function, com.aol.cyclops2.function.Monoid)
}
{@code
BinaryOperator> sumMaybes = SemigroupK.combineScalarFunctors(SemigroupK.intSum);
Maybe.just(1).zip(sumMaybes, Maybe.just(5))
//Maybe.just(6));
}
default <R> AnyMValue2<W,T2,R> coflatMap(java.util.function.Function<? super MonadicValue<T>,R> mapper)
MonadicValue
Maybe.none().coflatMap(m -> m.isPresent() ? m.get() : 10);
//Maybe[10]
coflatMap
in interface AnyMValue<W extends WitnessType<W>,T>
coflatMap
in interface MonadicValue<T>
mapper
- Mapping / transformation functiondefault AnyMValue<W,MonadicValue<T>> nest()
MonadicValue
nest
in interface AnyMValue<W extends WitnessType<W>,T>
nest
in interface MonadicValue<T>
default AnyMValue2<W,T2,T> combineEager(Monoid<T> monoid, AnyMValue<W,? extends T> v2)
combineEager
in interface AnyMValue<W extends WitnessType<W>,T>
default java.lang.String mkString()
Value
default <R> AnyMValue2<W,T2,R> zipWith(java.lang.Iterable<java.util.function.Function<? super T,? extends R>> fn)
default <R> AnyMValue2<W,T2,R> zipWithS(java.util.stream.Stream<java.util.function.Function<? super T,? extends R>> fn)
default <R> AnyMValue2<W,T2,R> zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super T,? extends R>> fn)
default <R> AnyMValue2<W,T2,R> retry(java.util.function.Function<? super T,? extends R> fn)
Transformable
given(serviceMock.applyHKT(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 AnyM<W extends WitnessType<W>,T>
retry
in interface AnyM2<W extends WitnessType<W>,T2,T>
retry
in interface AnyMValue<W extends WitnessType<W>,T>
retry
in interface Transformable<T>
fn
- Function to retry if failsdefault <U> AnyMValue2<W,T2,org.jooq.lambda.tuple.Tuple2<T,U>> zipP(org.reactivestreams.Publisher<? extends U> other)
default <R> AnyMValue2<W,T2,R> retry(java.util.function.Function<? super T,? extends R> fn, int retries, long delay, java.util.concurrent.TimeUnit timeUnit)
Transformable
given(serviceMock.applyHKT(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 AnyM<W extends WitnessType<W>,T>
retry
in interface AnyM2<W extends WitnessType<W>,T2,T>
retry
in interface AnyMValue<W extends WitnessType<W>,T>
retry
in interface Transformable<T>
fn
- Function to retry if failsretries
- Number of retriesdelay
- Delay in TimeUnitstimeUnit
- TimeUnit to use for delaydefault <S,U> AnyMValue2<W,T2,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> AnyMValue2<W,T2,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> AnyMValue2<W,T2,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> AnyMValue2<W,T2,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> AnyMValue2<W,T2,U> ofType(java.lang.Class<? extends U> type)
Filters
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
default AnyMValue2<W,T2,T> filterNot(java.util.function.Predicate<? super T> fn)
Filters
of(1,2,3).filter(i->i>2);
//[1,2]
filterNot
in interface AnyM<W extends WitnessType<W>,T>
filterNot
in interface AnyMValue<W extends WitnessType<W>,T>
filterNot
in interface Filters<T>
fn
- to filter elements by, retaining matchesdefault AnyMValue2<W,T2,T> notNull()
Filters
of(1,2,null,4).nonNull();
//[1,2,4]
default <U> AnyMValue2<W,T2,U> cast(java.lang.Class<? extends U> type)
Transformable
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)cast
in interface AnyM<W extends WitnessType<W>,T>
cast
in interface AnyMValue<W extends WitnessType<W>,T>
cast
in interface Transformable<T>
default <R> AnyMValue2<W,T2,R> trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Transformable
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 AnyM<W extends WitnessType<W>,T>
trampoline
in interface AnyMValue<W extends WitnessType<W>,T>
trampoline
in interface Transformable<T>
mapper
- TCO Transformation functiondefault <T> AnyMValue2<W,T2,T> emptyUnit()
emptyUnit
in interface AnyM<W extends WitnessType<W>,T>
emptyUnit
in interface AnyM2<W extends WitnessType<W>,T2,T>
emptyUnit
in interface AnyMValue<W extends WitnessType<W>,T>
emptyUnit
in interface EmptyUnit<T>
default AnyMValue2<W,T2,T> filter(java.util.function.Predicate<? super T> p)
AnyM2
AnyM.fromOptional(Optional.of(10)).filter(i->i<10);
//AnyM[Optional.zero()]
AnyM.fromStream(Stream.of(5,10)).filter(i->i<10);
//AnyM[Stream[5]]
filter
in interface AnyM<W extends WitnessType<W>,T>
filter
in interface AnyM2<W extends WitnessType<W>,T2,T>
filter
in interface AnyMValue<W extends WitnessType<W>,T>
filter
in interface Filters<T>
filter
in interface MonadicValue<T>
p
- Filtering predicatedefault <R> AnyMValue2<W,T2,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 AnyM<W extends WitnessType<W>,T>
map
in interface AnyM2<W extends WitnessType<W>,T2,T>
map
in interface AnyMValue<W extends WitnessType<W>,T>
map
in interface MonadicValue<T>
map
in interface Transformable<T>
fn
- Transformation functiondefault AnyMValue2<W,T2,T> peek(java.util.function.Consumer<? super T> c)
AnyM2
AnyM.fromCompletableFuture(CompletableFuture.supplyAsync(()->loadData())
.peek(System.out::println)
peek
in interface AnyM<W extends WitnessType<W>,T>
peek
in interface AnyM2<W extends WitnessType<W>,T2,T>
peek
in interface AnyMValue<W extends WitnessType<W>,T>
peek
in interface Transformable<T>
c
- Consumer to accept current datadefault int arity()
arity
in interface AnyMValue<W extends WitnessType<W>,T>
arity
in interface MonadicValue<T>
default boolean isPresent()
isPresent
in interface AnyMValue<W extends WitnessType<W>,T>
isPresent
in interface Convertable<T>
default AnyMValue<W,java.util.List<T>> aggregate(AnyM<W,T> next)
AnyM
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)));
default <R> AnyMValue2<W,T2,R> flatMapA(java.util.function.Function<? super T,? extends AnyM<W,? extends R>> fn)
default <R> AnyMValue2<W,T2,R> flatMapI(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> fn)
MonadicValue
Maybe.just(1).map(i->i+2).flatMapI(i->Arrays.asList(()->i*3,20);
//Maybe[9]
flatMapI
in interface AnyM<W extends WitnessType<W>,T>
flatMapI
in interface AnyM2<W extends WitnessType<W>,T2,T>
flatMapI
in interface AnyMValue<W extends WitnessType<W>,T>
flatMapI
in interface MonadicValue<T>
fn
- transformation functiondefault <R> AnyMValue2<W,T2,R> flatMapP(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> fn)
MonadicValue
Future.ofResult(1).map(i->i+2).flatMapP(i->Flux.just(()->i*3,20);
//Future[9]
flatMapP
in interface AnyM<W extends WitnessType<W>,T>
flatMapP
in interface AnyM2<W extends WitnessType<W>,T2,T>
flatMapP
in interface AnyMValue<W extends WitnessType<W>,T>
flatMapP
in interface MonadicValue<T>
fn
- transformation functiondefault <R> AnyMValue2<W,T2,R> flatMapS(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> fn)
default <R> AnyMValue2<W,T2,R> flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> fn)
MonadicValue
Optional.flatMap(Function)
Eval.now(1).map(i->i+2).flatMap(i->Eval.later(()->i*3);
//Eval[9]
flatMap
in interface AnyMValue<W extends WitnessType<W>,T>
flatMap
in interface MonadicValue<T>
fn
- transformation functiondefault T get()
get
in interface AnyMValue<W extends WitnessType<W>,T>
get
in interface Convertable<T>
get
in interface java.util.function.Supplier<T>
default <T> AnyMValue2<W,T2,T> unit(T value)
AnyM2
AnyM<Integer> ints = AnyM.fromList(Arrays.asList(1,2,3);
AnyM<String> string = ints.unit("hello");
unit
in interface AnyM<W extends WitnessType<W>,T>
unit
in interface AnyM2<W extends WitnessType<W>,T2,T>
unit
in interface AnyMValue<W extends WitnessType<W>,T>
unit
in interface MonadicValue<T>
unit
in interface Unit<T>
value
- to embed inside the monad wrapped by AnyMdefault <T> AnyMValue2<W,T2,T> empty()
AnyM2
Any<Integer> ints = AnyM.fromStream(Stream.of(1,2,3));
AnyM<Integer> zero=ints.zero();
default Xor<AnyMValue<W,T>,AnyMSeq<W,T>> matchable()
AnyM2
AnyM<String> monad;
monad.matchable().visit(v->handleValue(v.get()),s->handleSequence(s.toList()));
default <T2,R> AnyMValue2<W,T2,R> combine(Value<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
MonadicValue
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
combine
in interface AnyMValue<W extends WitnessType<W>,T>
combine
in interface MonadicValue<T>
app
- Value to combine with this one.fn
- BiFunction to combine themdefault <T2,R> AnyMValue2<W,T2,R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippable
default <T2,R> AnyMValue2<W,T2,R> zipP(org.reactivestreams.Publisher<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippable
zipP
in interface AnyM<W extends WitnessType<W>,T>
zipP
in interface AnyMValue<W extends WitnessType<W>,T>
zipP
in interface MonadicValue<T>
zipP
in interface Zippable<T>
app
- to combine withfn
- Zip / combining functiondefault java.util.Iterator<T> iterator()
iterator
in interface AnyM<W extends WitnessType<W>,T>
iterator
in interface AnyM2<W extends WitnessType<W>,T2,T>
iterator
in interface AnyMValue<W extends WitnessType<W>,T>
iterator
in interface Convertable<T>
iterator
in interface java.lang.Iterable<T>
iterator
in interface Value<T>
default ReactiveSeq<T> stream()
stream
in interface AnyM<W extends WitnessType<W>,T>
stream
in interface AnyM2<W extends WitnessType<W>,T2,T>
stream
in interface AnyMValue<W extends WitnessType<W>,T>
stream
in interface Folds<T>
stream
in interface ToStream<T>
stream
in interface Value<T>
default <T2,R1,R2,R3,R> AnyMValue2<W,T2,R> forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3, Fn4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c+d);
//Maybe.none
forEach4
in interface AnyMValue<W extends WitnessType<W>,T>
forEach4
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overvalue3
- Nested MonadicValue to iterate overyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R3,R> AnyMValue2<W,T2,R> forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3, Fn4<? super T,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction, Fn4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c<100,
(a,b,c,d)->a+b+c+d);
//Maybe.none
forEach4
in interface AnyMValue<W extends WitnessType<W>,T>
forEach4
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overvalue3
- Nested MonadicValue to iterate overfilterFunction
- Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R> AnyMValue2<W,T2,R> forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach3(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->a+b+c<100,
(a,b,c)->a+b+c);
//Maybe[32]
forEach3
in interface AnyMValue<W extends WitnessType<W>,T>
forEach3
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R> AnyMValue2<W,T2,R> forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super T,? super R1,? super R2,java.lang.Boolean> filterFunction, Fn3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach3(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->a+b+c<100,
(a,b,c)->a+b+c);
//Maybe[32]
forEach3
in interface AnyMValue<W extends WitnessType<W>,T>
forEach3
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overfilterFunction
- Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <R1,R> AnyMValue2<W,T2,R> forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
(a,b)->a+b);
//Maybe.none()
forEach2
in interface AnyMValue<W extends WitnessType<W>,T>
forEach2
in interface MonadicValue<T>
value1
- Nested Monadic Type to iterate overyieldingFunction
- Function with pointers to the current element from both
monad types that generates the new elementsdefault <R1,R> AnyMValue2<W,T2,R> forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,java.lang.Boolean> filterFunction, java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
a->b-> a<3 && b>10,
(a,b)->a+b);
//Maybe.none()
forEach2
in interface AnyMValue<W extends WitnessType<W>,T>
forEach2
in interface MonadicValue<T>
filterFunction
- Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
Streams that generates the new elementsdefault AnyMValue2<W,T2,T> combineEager(Monoid<T> monoid, MonadicValue<? extends T> v2)
MonadicValue
Monoid<Integer> add = Monoid.of(1,SemigroupK.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 , SemigroupK.firstNonNull());
Maybe.of(10).combineEager(firstNonNull,Maybe.of(10));
//Maybe[10]
combineEager
in interface AnyMValue<W extends WitnessType<W>,T>
combineEager
in interface MonadicValue<T>