LT1
- First type (Left type)LT2
- Second typeLT3
- Third TypeRT
- Right type (operations are performed on this type if present)public interface Either4<LT1,LT2,LT3,RT> extends Transformable<RT>, Filters<RT>, BiFunctor<LT3,RT>, To<Either4<LT1,LT2,LT3,RT>>, MonadicValue<RT>, java.util.function.Supplier<RT>
Modifier and Type | Interface and Description |
---|---|
static class |
Either4.Lazy<ST,M,M2,PT> |
static class |
Either4.Left1<ST,M,M2,PT> |
static class |
Either4.Left2<ST,M,M2,PT> |
static class |
Either4.Left3<ST,M,M2,PT> |
static class |
Either4.Right<ST,M,M2,PT> |
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Fn0.FunctionalOperations<R>, Fn0.Instances, Fn0.SupplierKind<R>
Modifier and Type | Method and Description |
---|---|
static <LT1,LT2,LT3,RT> |
accumulate(Monoid<RT> reducer,
CollectionX<Either4<LT1,LT2,LT3,RT>> xors)
Accumulate the results only from those Either3 which have a Right type present, using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
com.aol.cyclops2.Monoids . |
static <X,LT1 extends X,LT2 extends X,LT3 extends X,RT extends X,R> |
applyAny(Either4<LT1,LT2,LT3,RT> either) |
default <U1,U2> Either4<LT1,LT2,U1,U2> |
bicast(java.lang.Class<U1> type1,
java.lang.Class<U2> type2)
Cast two data types simulatanously.
|
<R1,R2> Either4<LT1,LT2,R1,R2> |
bimap(java.util.function.Function<? super LT3,? extends R1> fn1,
java.util.function.Function<? super RT,? extends R2> fn2)
Transform this BiFunctor, changing two value types at once.
|
default Either4<LT1,LT2,LT3,RT> |
bipeek(java.util.function.Consumer<? super LT3> c1,
java.util.function.Consumer<? super RT> c2)
Peek at two data types simulatanously (typically to perform a side-effect with each data point)
|
default <R1,R2> Either4<LT1,LT2,R1,R2> |
bitrampoline(java.util.function.Function<? super LT3,? extends Trampoline<? extends R1>> mapper1,
java.util.function.Function<? super RT,? extends Trampoline<? extends R2>> mapper2)
Perform a tail-call optimized recursive transformation operation across two data points simultaneously
|
default <U> Either4<LT1,LT2,LT3,U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
default <R> Either4<LT1,LT2,LT3,R> |
coflatMap(java.util.function.Function<? super MonadicValue<RT>,R> mapper)
Perform a coflatMap operation.
|
default <T2,R> Either4<LT1,LT2,LT3,R> |
combine(Value<? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Lazily combine this ApplicativeFunctor with the supplied value via the supplied BiFunction
Example
|
default Either4<LT1,LT2,LT3,RT> |
combineEager(Monoid<RT> monoid,
MonadicValue<? extends RT> v2)
Eagerly combine two MonadicValues using the supplied monoid (@see ApplicativeFunctor for type appropraite i.e.
|
static <X,LT1 extends X,LT2 extends X,LT3 extends X,RT extends X> |
consumeAny(Either4<LT1,LT2,LT3,RT> either)
Static method useful as a method reference for fluent consumption of any value type stored in this Either
(will capture the lowest common type)
|
Maybe<RT> |
filter(java.util.function.Predicate<? super RT> test)
Filter this Either4 resulting in a Maybe#none if it is not a Right instance or if the predicate does not
hold.
|
default Maybe<RT> |
filterNot(java.util.function.Predicate<? super RT> predicate)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<RT1> Either4<LT1,LT2,LT3,RT1> |
flatMap(java.util.function.Function<? super RT,? extends MonadicValue<? extends RT1>> mapper)
Flattening transformation on this Either4.
|
default <RT1> Either4<LT1,LT2,LT3,RT1> |
flatMapI(java.util.function.Function<? super RT,? extends java.lang.Iterable<? extends RT1>> mapper)
A flattening transformation operation that takes the first value from the returned Iterable.
|
default <RT1> Either4<LT1,LT2,LT3,RT1> |
flatMapP(java.util.function.Function<? super RT,? extends org.reactivestreams.Publisher<? extends RT1>> mapper)
A flattening transformation operation that takes the first value from the returned Publisher.
|
default <R> Either4<LT1,LT2,LT3,R> |
flatMapS(java.util.function.Function<? super RT,? extends java.util.stream.Stream<? extends R>> mapper) |
default <R1,R> Either4<LT1,LT2,LT3,R> |
forEach2(java.util.function.Function<? super RT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied MonadicValue
|
default <R1,R> Either4<LT1,LT2,LT3,R> |
forEach2(java.util.function.Function<? super RT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,java.lang.Boolean> filterFunction,
java.util.function.BiFunction<? super RT,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied stream
|
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super RT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super RT,? 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 RT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super RT,? super R1,? super R2,java.lang.Boolean> filterFunction,
Fn3<? super RT,? 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 RT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super RT,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Fn4<? super RT,? 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 RT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super RT,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Fn4<? super RT,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction,
Fn4<? super RT,? 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
|
static <ST,T,T2,RT> |
fromIterable(java.lang.Iterable<RT> iterable)
Construct a Right Either4 from the supplied Iterable
|
static <LT1,LT2,LT3,RT> |
fromMonadicValue(MonadicValue<RT> mv4) |
static <T1,T2,T> Either4<java.lang.Throwable,T1,T2,T> |
fromPublisher(org.reactivestreams.Publisher<T> pub)
Lazily construct a Right Either from the supplied publisher
|
boolean |
isLeft1() |
boolean |
isLeft2() |
boolean |
isLeft3() |
boolean |
isRight() |
static <LT,M1,B,RT> |
left1(LT left)
Construct a Either4#Left1
|
static <LT,M1,B,RT> |
left1Eval(Eval<LT> left)
Construct a Either4#Left1 from an Eval
|
static <LT,M1,B,RT> |
left2(M1 middle)
Construct a Either4#Second
|
static <LT,M1,B,RT> |
left2Eval(Eval<M1> middle)
Construct a Either4#Second from an Eval
|
static <LT,M1,B,RT> |
left3(B middle)
Construct a Either4#Third
|
static <LT,M1,B,RT> |
left3Eval(Eval<B> middle)
Construct a Either4#Third from an Eval
|
<R> Either4<LT1,LT2,LT3,R> |
map(java.util.function.Function<? super RT,? extends R> fn)
Transform this functor using the supplied transformation function
|
default Either4<LT1,LT2,LT3,MonadicValue<RT>> |
nest()
cojoin pattern.
|
default Maybe<RT> |
notNull()
Filter elements retaining only values which are not null
|
default <U> Maybe<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
default Either4<LT1,LT2,LT3,RT> |
peek(java.util.function.Consumer<? super RT> c)
Peek at the current value of this Transformable, without transforming it
|
default <R> Either4<LT1,LT2,LT3,R> |
retry(java.util.function.Function<? super RT,? extends R> fn)
Retry a transformation if it fails.
|
default <R> Either4<LT1,LT2,LT3,R> |
retry(java.util.function.Function<? super RT,? extends R> fn,
int retries,
long delay,
java.util.concurrent.TimeUnit timeUnit)
Retry a transformation if it fails.
|
static <LT,M1,B,RT> |
right(RT right)
Construct a Either4#Right
|
static <LT,M1,B,RT> |
rightEval(Eval<RT> right)
Construct a Either4#Right from an Eval
|
static <LT1,LT2,LT3,PT> |
sequence(CollectionX<Either4<LT1,LT2,LT3,PT>> xors)
Turn a collection of Either3 into a single Either with Lists of values.
|
Either4<RT,LT2,LT3,LT1> |
swap1() |
Either4<LT1,RT,LT3,LT2> |
swap2() |
Either4<LT1,LT2,RT,LT3> |
swap3() |
default Ior<LT1,RT> |
toIor()
Return an Ior that can be this object or a Ior.primary or Ior.secondary
|
default Xor<LT1,RT> |
toXor() |
default <R> Either4<LT1,LT2,LT3,R> |
trampoline(java.util.function.Function<? super RT,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
static <LT1,LT2,LT3,PT,R> |
traverse(CollectionX<Either4<LT1,LT2,LT3,PT>> xors,
java.util.function.Function<? super PT,? extends R> fn)
Traverse a Collection of Either3 producing an Either4 with a ListX, applying the transformation function to every
element in the list
|
<T> Either4<LT1,LT2,LT3,T> |
unit(T unit) |
<R> R |
visit(java.util.function.Function<? super LT1,? extends R> left1,
java.util.function.Function<? super LT2,? extends R> left2,
java.util.function.Function<? super LT3,? extends R> left3,
java.util.function.Function<? super RT,? extends R> right)
Visit the types in this Either4, only one user supplied function is executed depending on the type
|
static <X,LT1 extends X,LT2 extends X,LT3 extends X,RT extends X> |
visitAny(java.util.function.Consumer<? super X> c,
Either4<LT1,LT2,LT3,RT> either) |
static <X,LT1 extends X,LT2 extends X,LT3 extends X,RT extends X,R> |
visitAny(Either4<LT1,LT2,LT3,RT> either,
java.util.function.Function<? super X,? extends R> fn) |
default Either4<LT1,LT2,LT3,RT> |
zip(java.util.function.BinaryOperator<Zippable<RT>> combiner,
Zippable<RT> app)
Combine two applicatives together using the provided BinaryOperator (Semigroup, Monoid and Reducer all
extend BinaryOperator - checkout Semigroups and Monoids for a large number of canned combinations).
|
default <T2,R> Either4<LT1,LT2,LT3,R> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Iterable using the supplied combining function
|
default <U> Either4<LT1,LT2,LT3,org.jooq.lambda.tuple.Tuple2<RT,U>> |
zip(java.lang.Iterable<? extends U> other)
Zip (combine) this Zippable with the supplied Iterable combining both into a Tuple2
|
default <S,U> Either4<LT1,LT2,LT3,org.jooq.lambda.tuple.Tuple3<RT,S,U>> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third)
zip 3 Streams into one
|
default <S,U,R> Either4<LT1,LT2,LT3,R> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third,
Fn3<? super RT,? super S,? super U,? extends R> fn3) |
default <T2,T3,T4> Either4<LT1,LT2,LT3,org.jooq.lambda.tuple.Tuple4<RT,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 RT,? super T2,? super T3,? super T4,? extends R> fn) |
default <T2,R> Either4<LT1,LT2,LT3,R> |
zipP(org.reactivestreams.Publisher<? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Publisher, using the supplied combining function
|
default <U> Either4<LT1,LT2,LT3,org.jooq.lambda.tuple.Tuple2<RT,U>> |
zipP(org.reactivestreams.Publisher<? extends U> other) |
default <U> Either4<LT1,LT2,LT3,org.jooq.lambda.tuple.Tuple2<RT,U>> |
zipS(java.util.stream.Stream<? extends U> other)
Zip (combine) this Zippable with the supplied Stream combining both into a Tuple2
|
default <U,R> Either4<LT1,LT2,LT3,R> |
zipS(java.util.stream.Stream<? extends U> other,
java.util.function.BiFunction<? super RT,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Stream, using the supplied combining function
|
default <R> Either4<LT1,LT2,LT3,R> |
zipWith(java.lang.Iterable<java.util.function.Function<? super RT,? extends R>> fn) |
default <R> Either4<LT1,LT2,LT3,R> |
zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super RT,? extends R>> fn) |
default <R> Either4<LT1,LT2,LT3,R> |
zipWithS(java.util.stream.Stream<java.util.function.Function<? super RT,? extends R>> fn) |
apply, generate, iterate, iterator, mkString, newSubscriber, of, stream, subscribe, test, toEvalAlways, toEvalLater, toEvalNow, toMaybe, toTry, toTry, toTry, toXor
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, toConcurrentLazyCollection, toConcurrentLazyStreamable, toLazyCollection, xMatch
futureStream, getStreamable, isEmpty, jdkStream, reactiveSeq, reveresedJDKStream, reveresedStream
collect, fromSupplier, get, isPresent, orElse, orElseGet, orElseThrow, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFuture, toFutureWAsync, toFutureWAsync, toOptional, toStream, visit
static <X,LT1 extends X,LT2 extends X,LT3 extends X,RT extends X> java.util.function.Consumer<java.util.function.Consumer<? super X>> consumeAny(Either4<LT1,LT2,LT3,RT> either)
myEither.to(Either4::consumeAny)
.accept(System.out::println);
either
- Either to consume value forstatic <X,LT1 extends X,LT2 extends X,LT3 extends X,RT extends X,R> java.util.function.Function<java.util.function.Function<? super X,R>,R> applyAny(Either4<LT1,LT2,LT3,RT> either)
static <X,LT1 extends X,LT2 extends X,LT3 extends X,RT extends X,R> R visitAny(Either4<LT1,LT2,LT3,RT> either, java.util.function.Function<? super X,? extends R> fn)
static <X,LT1 extends X,LT2 extends X,LT3 extends X,RT extends X> X visitAny(java.util.function.Consumer<? super X> c, Either4<LT1,LT2,LT3,RT> either)
static <LT1,LT2,LT3,RT> Either4<LT1,LT2,LT3,RT> fromMonadicValue(MonadicValue<RT> mv4)
static <LT1,LT2,LT3,PT> Either4<ListX<LT1>,ListX<LT2>,ListX<LT3>,ListX<PT>> sequence(CollectionX<Either4<LT1,LT2,LT3,PT>> xors)
Either4<String,String,String,Integer> just = Either4.right(10);
Either4<String,String,String,Integer> none = Either4.left("none");
Either4<ListX<String>,ListX<String>,ListX<String>,ListX<Integer>> xors =Either4.sequence(ListX.of(just,none,Either4.right(1)));
//Eitehr.right(ListX.of(10,1)));
Either3
- Either3 to sequencestatic <LT1,LT2,LT3,PT,R> Either4<ListX<LT1>,ListX<LT2>,ListX<LT3>,ListX<R>> traverse(CollectionX<Either4<LT1,LT2,LT3,PT>> xors, java.util.function.Function<? super PT,? extends R> fn)
xors
- Either4s to sequence and transformfn
- Transformation functionstatic <LT1,LT2,LT3,RT> Either4<ListX<LT1>,ListX<LT2>,ListX<LT3>,RT> accumulate(Monoid<RT> reducer, CollectionX<Either4<LT1,LT2,LT3,RT>> xors)
com.aol.cyclops2.Monoids
.
Either4<String,String,String,Integer> just = Either4.right(10);
Either4<String,String,String,Integer> none = Either4.left("none");
Either4<ListX<String>,ListX<String>,Integer> xors = Either4.accumulatePrimary(Monoids.intSum,ListX.of(just,none,Either4.right(1)));
//Either4.right(11);
xors
- Collection of Eithers to accumulate primary valuesreducer
- Reducer to accumulate resultsstatic <T1,T2,T> Either4<java.lang.Throwable,T1,T2,T> fromPublisher(org.reactivestreams.Publisher<T> pub)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
Either4<Throwable,String,String,Integer> either = Either4.fromPublisher(stream);
//Either[1]
pub
- Publisher to construct an Either fromstatic <ST,T,T2,RT> Either4<ST,T,T2,RT> fromIterable(java.lang.Iterable<RT> iterable)
List<Integer> list = Arrays.asList(1,2,3);
Either4<Throwable,String,Integer> future = Either4.fromIterable(list);
//Either4[1]
iterable
- Iterable to construct an Either fromstatic <LT,M1,B,RT> Either4<LT,M1,B,RT> rightEval(Eval<RT> right)
right
- Eval to construct Either4#Right fromstatic <LT,M1,B,RT> Either4<LT,M1,B,RT> left1Eval(Eval<LT> left)
left
- Eval to construct Either4#Left1 fromstatic <LT,M1,B,RT> Either4<LT,M1,B,RT> right(RT right)
right
- Value to storestatic <LT,M1,B,RT> Either4<LT,M1,B,RT> left1(LT left)
left
- Value to storestatic <LT,M1,B,RT> Either4<LT,M1,B,RT> left2(M1 middle)
middle
- Value to storestatic <LT,M1,B,RT> Either4<LT,M1,B,RT> left3(B middle)
middle
- Value to storestatic <LT,M1,B,RT> Either4<LT,M1,B,RT> left2Eval(Eval<M1> middle)
second
- Eval to construct Either4#middle fromstatic <LT,M1,B,RT> Either4<LT,M1,B,RT> left3Eval(Eval<B> middle)
third
- Eval to construct Either4#middle fromdefault <R> Either4<LT1,LT2,LT3,R> zipWith(java.lang.Iterable<java.util.function.Function<? super RT,? extends R>> fn)
default <R> Either4<LT1,LT2,LT3,R> zipWithS(java.util.stream.Stream<java.util.function.Function<? super RT,? extends R>> fn)
default <R> Either4<LT1,LT2,LT3,R> zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super RT,? extends R>> fn)
default <R> Either4<LT1,LT2,LT3,R> retry(java.util.function.Function<? super RT,? 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<RT>
fn
- Function to retry if failsdefault <U> Either4<LT1,LT2,LT3,org.jooq.lambda.tuple.Tuple2<RT,U>> zipP(org.reactivestreams.Publisher<? extends U> other)
default <R> Either4<LT1,LT2,LT3,R> retry(java.util.function.Function<? super RT,? 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<RT>
fn
- Function to retry if failsretries
- Number of retriesdelay
- Delay in TimeUnitstimeUnit
- TimeUnit to use for delaydefault <S,U> Either4<LT1,LT2,LT3,org.jooq.lambda.tuple.Tuple3<RT,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(Collectors.toList());
// [[1,100,'a'],[2,200,'b'],[3,300,'c']]
default <S,U,R> Either4<LT1,LT2,LT3,R> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third, Fn3<? super RT,? super S,? super U,? extends R> fn3)
default <T2,T3,T4> Either4<LT1,LT2,LT3,org.jooq.lambda.tuple.Tuple4<RT,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(Collectors.toList());
// [[1,100,'a',"hello"],[2,200,'b',"world"]]
default <T2,T3,T4,R> Either4<LT1,LT2,LT3,R> zip4(java.lang.Iterable<? extends T2> second, java.lang.Iterable<? extends T3> third, java.lang.Iterable<? extends T4> fourth, Fn4<? super RT,? super T2,? super T3,? super T4,? extends R> fn)
default <R> Either4<LT1,LT2,LT3,R> flatMapS(java.util.function.Function<? super RT,? extends java.util.stream.Stream<? extends R>> mapper)
flatMapS
in interface MonadicValue<RT>
default <RT1> Either4<LT1,LT2,LT3,RT1> flatMapI(java.util.function.Function<? super RT,? extends java.lang.Iterable<? extends RT1>> mapper)
MonadicValue
Maybe.just(1).map(i->i+2).flatMapI(i->Arrays.asList(()->i*3,20);
//Maybe[9]
flatMapI
in interface MonadicValue<RT>
mapper
- transformation functiondefault <RT1> Either4<LT1,LT2,LT3,RT1> flatMapP(java.util.function.Function<? super RT,? extends org.reactivestreams.Publisher<? extends RT1>> mapper)
MonadicValue
FutureW.ofResult(1).map(i->i+2).flatMapP(i->Flux.just(()->i*3,20);
//FutureW[9]
flatMapP
in interface MonadicValue<RT>
mapper
- transformation function<R> R visit(java.util.function.Function<? super LT1,? extends R> left1, java.util.function.Function<? super LT2,? extends R> left2, java.util.function.Function<? super LT3,? extends R> left3, java.util.function.Function<? super RT,? extends R> right)
left1
- Function to execute if this Either4 is a Left1 instanceleft2
- Function to execute if this Either4 is a Left2 instanceleft3
- Function to execute if this Either4 is a Left3 instanceright
- Function to execute if this Either4 is a right instanceMaybe<RT> filter(java.util.function.Predicate<? super RT> test)
<RT1> Either4<LT1,LT2,LT3,RT1> flatMap(java.util.function.Function<? super RT,? extends MonadicValue<? extends RT1>> mapper)
flatMap
in interface MonadicValue<RT>
mapper
- Mapping functionboolean isRight()
boolean isLeft1()
boolean isLeft2()
boolean isLeft3()
default <U> Maybe<U> ofType(java.lang.Class<? extends U> type)
Filters
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
default Maybe<RT> filterNot(java.util.function.Predicate<? super RT> predicate)
Filters
of(1,2,3).filter(i->i>2);
//[1,2]
default Maybe<RT> notNull()
Filters
of(1,2,null,4).nonNull();
//[1,2,4]
<R1,R2> Either4<LT1,LT2,R1,R2> bimap(java.util.function.Function<? super LT3,? extends R1> fn1, java.util.function.Function<? super RT,? extends R2> fn2)
BiFunctor
MapX<String,Integer> map = MapXs.of("hello",2);
MapX<String,Integer> transformedMap = map.bimap(s->s+" world",i->i*4);
//["hello world",8]
<R> Either4<LT1,LT2,LT3,R> map(java.util.function.Function<? super RT,? extends R> fn)
Transformable
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface MonadicValue<RT>
map
in interface Transformable<RT>
fn
- Transformation functiondefault Ior<LT1,RT> toIor()
default <R> Either4<LT1,LT2,LT3,R> coflatMap(java.util.function.Function<? super MonadicValue<RT>,R> mapper)
MonadicValue
Maybe.none().coflatMap(m -> m.isPresent() ? m.get() : 10);
//Maybe[10]
coflatMap
in interface MonadicValue<RT>
mapper
- Mapping / transformation functiondefault Either4<LT1,LT2,LT3,MonadicValue<RT>> nest()
MonadicValue
nest
in interface MonadicValue<RT>
default <T2,R1,R2,R3,R> Either4<LT1,LT2,LT3,R> forEach4(java.util.function.Function<? super RT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super RT,? super R1,? super R2,? extends MonadicValue<R3>> value3, Fn4<? super RT,? 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 MonadicValue<RT>
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> Either4<LT1,LT2,LT3,R> forEach4(java.util.function.Function<? super RT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super RT,? super R1,? super R2,? extends MonadicValue<R3>> value3, Fn4<? super RT,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction, Fn4<? super RT,? 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 MonadicValue<RT>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overvalue3
- Nested MonadicValue to iterate overfilterFunction
- Filter to apply 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> Either4<LT1,LT2,LT3,R> forEach3(java.util.function.Function<? super RT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super RT,? 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 MonadicValue<RT>
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> Either4<LT1,LT2,LT3,R> forEach3(java.util.function.Function<? super RT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super RT,? super R1,? super R2,java.lang.Boolean> filterFunction, Fn3<? super RT,? 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 MonadicValue<RT>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overfilterFunction
- Filter to apply 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> Either4<LT1,LT2,LT3,R> forEach2(java.util.function.Function<? super RT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
(a,b)->a+b);
//Maybe.none()
forEach2
in interface MonadicValue<RT>
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> Either4<LT1,LT2,LT3,R> forEach2(java.util.function.Function<? super RT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super RT,? super R1,java.lang.Boolean> filterFunction, java.util.function.BiFunction<? super RT,? 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 MonadicValue<RT>
filterFunction
- Filter to apply 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 Either4<LT1,LT2,LT3,RT> combineEager(Monoid<RT> monoid, MonadicValue<? extends RT> v2)
MonadicValue
Monoid<Integer> add = Monoid.of(1,Semigroups.intSum);
Maybe.of(10).combineEager(add,Maybe.none());
//Maybe[10]
Maybe.none().combineEager(add,Maybe.of(10));
//Maybe[10]
Maybe.none().combineEager(add,Maybe.none());
//Maybe.none()
Maybe.of(10).combineEager(add,Maybe.of(10));
//Maybe[20]
Monoid<Integer> firstNonNull = Monoid.of(null , Semigroups.firstNonNull());
Maybe.of(10).combineEager(firstNonNull,Maybe.of(10));
//Maybe[10]
combineEager
in interface MonadicValue<RT>
default <T2,R> Either4<LT1,LT2,LT3,R> combine(Value<? extends T2> app, java.util.function.BiFunction<? super RT,? 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 MonadicValue<RT>
app
- Value to combine with this one.fn
- BiFunction to combine themdefault Either4<LT1,LT2,LT3,RT> zip(java.util.function.BinaryOperator<Zippable<RT>> combiner, Zippable<RT> app)
Zippable
zip
in interface Zippable<RT>
Semigroup
,
Semigroups
,
Monoid
,
To lift any Semigroup (or monoid) up to handling Applicatives use the combineApplicatives operator in Semigroups
{@see com.aol.cyclops2.Semigroups#combineApplicatives(BiFunction) } or Monoids
{ {@see com.aol.cyclops2.Monoids#combineApplicatives(java.util.function.Function, com.aol.cyclops2.function.Monoid)
}
{@code
BinaryOperator> sumMaybes = Semigroups.combineScalarFunctors(Semigroups.intSum);
Maybe.just(1).zip(sumMaybes, Maybe.just(5))
//Maybe.just(6));
}
default <U,R> Either4<LT1,LT2,LT3,R> zipS(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super RT,? super U,? extends R> zipper)
Zippable
default <U> Either4<LT1,LT2,LT3,org.jooq.lambda.tuple.Tuple2<RT,U>> zipS(java.util.stream.Stream<? extends U> other)
Zippable
default <U> Either4<LT1,LT2,LT3,org.jooq.lambda.tuple.Tuple2<RT,U>> zip(java.lang.Iterable<? extends U> other)
Zippable
default <T2,R> Either4<LT1,LT2,LT3,R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Zippable
default <T2,R> Either4<LT1,LT2,LT3,R> zipP(org.reactivestreams.Publisher<? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Zippable
default Either4<LT1,LT2,LT3,RT> bipeek(java.util.function.Consumer<? super LT3> c1, java.util.function.Consumer<? super RT> c2)
BiFunctor
MapX<String,Integer> map = MapXs.of("hello",2);
map.bipeek(s->System.out.pritnln("key = " + s),System.out::println);
default <U1,U2> Either4<LT1,LT2,U1,U2> bicast(java.lang.Class<U1> type1, java.lang.Class<U2> type2)
BiFunctor
MapX<Animal,Food> map = MapXs.of(cow,grass);
MapX<Mamaml,Vegitation> herbervoreMammals = map.bicast(Mammal.class,Vegitation.class);
default <R1,R2> Either4<LT1,LT2,R1,R2> bitrampoline(java.util.function.Function<? super LT3,? extends Trampoline<? extends R1>> mapper1, java.util.function.Function<? super RT,? extends Trampoline<? extends R2>> mapper2)
BiFunctor
bitrampoline
in interface BiFunctor<LT3,RT>
mapper1
- transformation function for the first typemapper2
- transformation function for the second typedefault <U> Either4<LT1,LT2,LT3,U> cast(java.lang.Class<? extends U> type)
Transformable
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)cast
in interface Transformable<RT>
default Either4<LT1,LT2,LT3,RT> peek(java.util.function.Consumer<? super RT> c)
Transformable
of(1,2,3).map(System.out::println)
1
2
3
peek
in interface Transformable<RT>
c
- Consumer that recieves each element from this Transformabledefault <R> Either4<LT1,LT2,LT3,R> trampoline(java.util.function.Function<? super RT,? 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 Transformable<RT>
mapper
- TCO Transformation function