LT
- Left typeRT
- Right typepublic interface Either<LT,RT> extends Xor<LT,RT>
public class Member{ Eitherteam; } Rather than public class Member{
Modifier and Type | Interface and Description |
---|---|
static class |
Either.CompletableEither<ORG,RT> |
static class |
Either.Lazy<ST,PT> |
static class |
Either.Left<ST,PT> |
static class |
Either.Right<ST,PT> |
Xor.Instances, Xor.Primary<ST,PT>, Xor.Secondary<ST,PT>
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Fn0.FunctionalOperations<R>, Fn0.SupplierKind<R>
Modifier and Type | Method and Description |
---|---|
static <LT1,RT> Either<ListX<LT1>,RT> |
accumulate(Monoid<RT> reducer,
CollectionX<Either<LT1,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 . |
default AnyM<Witness.either,RT> |
anyMEither() |
static <X,LT extends X,M extends X,RT extends X,R> |
applyAny(Either<LT,RT> either) |
static <RT> Either<java.lang.Throwable,RT> |
async(java.util.concurrent.Executor ex,
java.util.function.Supplier<RT> s) |
default <U1,U2> Either<U1,U2> |
bicast(java.lang.Class<U1> type1,
java.lang.Class<U2> type2)
Cast two data types simulatanously.
|
default <R1,R2> Either<R1,R2> |
bimap(java.util.function.Function<? super LT,? extends R1> secondary,
java.util.function.Function<? super RT,? extends R2> primary)
Transform this BiTransformable, changing two value types at once.
|
default Either<LT,RT> |
bipeek(java.util.function.Consumer<? super LT> 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> Either<R1,R2> |
bitrampoline(java.util.function.Function<? super LT,? 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> Either<LT,U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a reactiveStream to a given type, possibly throwing a
ClassCastException . |
default <R> Either<LT,R> |
coflatMap(java.util.function.Function<? super MonadicValue<RT>,R> mapper)
Perform a coflatMap operation.
|
default <T2,R> Either<LT,R> |
combine(Either<? extends LT,? extends T2> app,
java.util.function.BinaryOperator<LT> semigroup,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Accumulate secondary values with the provided BinaryOperator / Semigroup
Semigroups
Right accumulation only occurs if all phases are primary |
<T2,R> Either<LT,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 <T2,R> Either<LT,R> |
combine(Xor<? extends LT,? extends T2> app,
java.util.function.BinaryOperator<LT> semigroup,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Accumulate secondary values with the provided BinaryOperator / Semigroup
Semigroups
Primary accumulation only occurs if all phases are primary |
default Either<LT,RT> |
combineEager(Monoid<RT> monoid,
MonadicValue<? extends RT> v2)
Eagerly combine two MonadicValues using the supplied monoid (@see ApplicativeFunctor for type appropraite i.e.
|
default <T2,R> Either<LinkedListX<LT>,R> |
combineToList(Either<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Accumulate secondarys into a LinkedListX (extended Persistent List) and Right with the supplied combiner function
Right accumulation only occurs if all phases are primary
|
default <T2,R> Either<LinkedListX<LT>,R> |
combineToList(Xor<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Accumulate secondarys into a LinkedListX (extended Persistent List) and Primary with the supplied combiner function
Primary accumulation only occurs if all phases are primary
|
static <X,LT extends X,M extends X,RT extends X> |
consumeAny(Either<LT,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)
|
static <RT> Either.CompletableEither<RT,RT> |
either()
Create a reactiveBuffer CompletableEither
|
Either<LT,RT> |
filter(java.util.function.Predicate<? super RT> test)
Keep only elements for which the supplied predicates hold
e.g.
|
default Either<LT,RT> |
filterNot(java.util.function.Predicate<? super RT> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<RT1> Either<LT,RT1> |
flatMap(java.util.function.Function<? super RT,? extends MonadicValue<? extends RT1>> mapper)
A flattening transformation operation (@see
Optional.flatMap(Function) |
default <R> Either<LT,R> |
flatMapI(java.util.function.Function<? super RT,? extends java.lang.Iterable<? extends R>> mapper)
A flattening transformation operation that takes the first value from the returned Iterable.
|
default <R> Either<LT,R> |
flatMapP(java.util.function.Function<? super RT,? extends org.reactivestreams.Publisher<? extends R>> mapper)
A flattening transformation operation that takes the first value from the returned Publisher.
|
default <R> Either<LT,R> |
flatMapS(java.util.function.Function<? super RT,? extends java.util.stream.Stream<? extends R>> mapper) |
default <R1,R> Either<LT,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> Either<LT,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 reactiveStream
|
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 <T> Either<java.lang.Throwable,T> |
fromFuture(Future<T> future) |
static <ST,T> Either<ST,T> |
fromIterable(java.lang.Iterable<T> iterable)
Construct a Right Either from the supplied Iterable
|
static <LT,RT> Either<LT,RT> |
fromLazy(Eval<Either<LT,RT>> lazy) |
static <LT1,RT> Either<LT1,RT> |
fromMonadicValue(MonadicValue<RT> mv2) |
static <T> Either<java.lang.Throwable,T> |
fromPublisher(org.reactivestreams.Publisher<T> pub)
Lazily construct a Right Either from the supplied publisher
|
static <ST,PT> Either<ST,PT> |
fromXor(Xor<ST,PT> xor) |
RT |
get() |
boolean |
isLeft() |
default boolean |
isPresent() |
default boolean |
isPrimary() |
boolean |
isRight() |
default boolean |
isSecondary() |
static <ST,PT> Either<ST,PT> |
left(ST value)
Create an instance of the secondary type.
|
static <LT,B,RT> Either<LT,RT> |
leftEval(Eval<LT> left) |
default Either<LinkedListX<LT>,RT> |
list() |
<R> Either<LT,R> |
map(java.util.function.Function<? super RT,? extends R> fn)
Transform this functor using the supplied transformation function
|
default <R1,R2> Either<R1,R2> |
mapBoth(java.util.function.Function<? super LT,? extends R1> secondary,
java.util.function.Function<? super RT,? extends R2> primary)
Deprecated.
|
static <ST,PT> Either<ST,PT> |
narrow(Either<? extends ST,? extends PT> broad) |
default Either<LT,MonadicValue<RT>> |
nest()
cojoin pattern.
|
default Either<LT,RT> |
notNull()
Filter elements retaining only values which are not null
|
default <U> Either<LT,U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a reactiveStream that are of a given type.
|
void |
peek(java.util.function.Consumer<? super LT> stAction,
java.util.function.Consumer<? super RT> ptAction)
Deprecated.
|
Either<LT,RT> |
peek(java.util.function.Consumer<? super RT> action)
Peek at the current value of this Transformable, without transforming it
|
default <R> Either<LT,R> |
retry(java.util.function.Function<? super RT,? extends R> fn)
Retry a transformation if it fails.
|
default <R> Either<LT,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 <ST,PT> Either<ST,PT> |
right(PT value)
Create an instance of the primary type.
|
static <LT,B,RT> Either<LT,RT> |
rightEval(Eval<RT> right) |
<LT1> Either<LT1,RT> |
secondaryFlatMap(java.util.function.Function<? super LT,? extends Xor<LT1,RT>> mapper)
Perform a flatMap operation on the Left type
|
LT |
secondaryGet() |
<R> Either<R,RT> |
secondaryMap(java.util.function.Function<? super LT,? extends R> fn)
Always map the Left type of this Either if it is present using the provided transformation function
|
Either<LT,RT> |
secondaryPeek(java.util.function.Consumer<? super LT> action)
Peek at the Left type value if present
|
java.util.Optional<LT> |
secondaryToOptional() |
Either<LT,RT> |
secondaryToPrimayFlatMap(java.util.function.Function<? super LT,? extends Xor<LT,RT>> fn)
A flatMap operation that keeps the Left and Right types the same
|
Either<LT,RT> |
secondaryToPrimayMap(java.util.function.Function<? super LT,? extends RT> fn)
If this Either contains the Left type, map it's value so that it contains the Right type
|
ReactiveSeq<LT> |
secondaryToStream() |
Value<LT> |
secondaryValue() |
static <LT1,PT> Either<ListX<LT1>,ListX<PT>> |
sequenceLeft(CollectionX<Either<LT1,PT>> xors) |
static <LT1,PT> Either<ListX<LT1>,ListX<PT>> |
sequenceRight(CollectionX<Either<LT1,PT>> xors)
Turn a toX of Eithers into a singleUnsafe Either with Lists of values.
|
Either<RT,LT> |
swap()
Swap types so operations directly affect the current (pre-swap) Left type
|
static <L,T,R> Either<L,R> |
tailRec(T initial,
java.util.function.Function<? super T,? extends Either<L,? extends Xor<T,R>>> fn) |
default Trampoline<Either<LT,RT>> |
toEitherTrampoline() |
Ior<LT,RT> |
toIor()
Return an Ior that can be this object or a Ior.primary or Ior.secondary
|
default java.util.Optional<RT> |
toOptional() |
default Trampoline<Xor<LT,RT>> |
toTrampoline() |
default Trampoline<RT> |
toTrampoline(RT defaultValue) |
default Trampoline<RT> |
toTrampoline(java.util.function.Supplier<RT> defaultValue) |
default Xor<LT,RT> |
toXor() |
default <ST2> Xor<ST2,RT> |
toXor(ST2 secondary)
Convert to an Xor where the secondary value will be used if no primary value is present
|
default <R> Either<LT,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,PT,R> Either<ListX<R>,ListX<PT>> |
traverseLeft(CollectionX<Either<LT1,PT>> xors,
java.util.function.Function<? super LT1,? extends R> fn) |
static <LT1,PT,R> Either<ListX<LT1>,ListX<R>> |
traverseRight(CollectionX<Either<LT1,PT>> xors,
java.util.function.Function<? super PT,? extends R> fn)
TraverseOps a Collection of Either producting an Either3 with a ListX, applying the transformation function to every
element in the list
|
default <T> Either<LT,T> |
unit(T unit) |
<R> R |
visit(java.util.function.Function<? super LT,? extends R> secondary,
java.util.function.Function<? super RT,? extends R> primary)
Visitor pattern for this Ior.
|
static <X,LT extends X,RT extends X> |
visitAny(java.util.function.Consumer<? super X> c,
Either<LT,RT> either) |
static <X,PT extends X,ST extends X,R> |
visitAny(Either<ST,PT> either,
java.util.function.Function<? super X,? extends R> fn) |
default Either<LT,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 SemigroupK and Monoids for a large number of canned combinations).
|
default <T2,R> Either<LT,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> Either<LT,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> Either<LT,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> Either<LT,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> Either<LT,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> Either<LT,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> Either<LT,org.jooq.lambda.tuple.Tuple2<RT,U>> |
zipP(org.reactivestreams.Publisher<? extends U> other) |
default <U> Either<LT,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> Either<LT,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> Either<LT,R> |
zipWith(java.lang.Iterable<java.util.function.Function<? super RT,? extends R>> fn) |
default <R> Either<LT,R> |
zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super RT,? extends R>> fn) |
default <R> Either<LT,R> |
zipWithS(java.util.stream.Stream<java.util.function.Function<? super RT,? extends R>> fn) |
accumulatePrimary, accumulatePrimary, accumulatePrimary, accumulateSecondary, accumulateSecondary, accumulateSecondary, allTypeclasses, anyM, applyAny, arity, consumeAny, coproduct, kindCokleisli, kindKleisli, liftM, mapM, narrowK, narrowK2, nested, nestedEval, primary, product, secondary, sequencePrimary, sequenceSecondary, tailRec, visitAny, visitAny, widen
apply, generate, iterate, iterator, mkString, newSubscriber, of, stream, subscribe, test, toEither, toEval, toEvalAlways, toEvalLater, toEvalNow, toLeft, toMaybe, toMaybeEager, toRight, toTry, toTry, toTry
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, singleUnsafe, startsWith, startsWithIterable, takeOne, xMatch
collect, fromSupplier, orElse, orElseGet, orElseThrow, toCompletableFuture, toCompletableFutureAsync, toFuture, toFutureAsync, toStream, visit
static <L,T,R> Either<L,R> tailRec(T initial, java.util.function.Function<? super T,? extends Either<L,? extends Xor<T,R>>> fn)
static <LT1,RT> Either<LT1,RT> fromMonadicValue(MonadicValue<RT> mv2)
static <RT> Either<java.lang.Throwable,RT> async(java.util.concurrent.Executor ex, java.util.function.Supplier<RT> s)
static <RT> Either.CompletableEither<RT,RT> either()
___Example 1___
CompletableEither<Integer,Integer> completable = Either.lazy();
Either<Throwable,Integer> mapped = completable.map(i->i*2)
.flatMap(i->Eval.later(()->i+1));
completable.complete(5);
mapped.printOut();
//11
___Example 2___
CompletableEither<Integer,Integer> completable = Either.lazy();
Either<Throwable,Integer> mapped = completable.map(i->i*2)
.flatMap(i->Eval.later(()->i+1));
completable.complete(null);
//Either:Left[NoSuchElementException]
___Example 3___
CompletableEither<Integer,Integer> completable = Either.lazy();
Either<Throwable,Integer> mapped = completable.map(i->i*2)
.flatMap(i->Eval.later(()->i+1));
completable.complete(new IllegalStateException());
//Either:Left[IllegalStateElementException]
RT
- static <LT1,PT> Either<ListX<LT1>,ListX<PT>> sequenceRight(CollectionX<Either<LT1,PT>> xors)
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<ListX<String>,ListX<Integer>> xors =Either.sequence(ListX.of(just,none,Either.right(1)));
//Eitehr.right(ListX.of(10,1)));
Either
- Either to sequencestatic <LT1,PT> Either<ListX<LT1>,ListX<PT>> sequenceLeft(CollectionX<Either<LT1,PT>> xors)
static <LT1,PT,R> Either<ListX<LT1>,ListX<R>> traverseRight(CollectionX<Either<LT1,PT>> xors, java.util.function.Function<? super PT,? extends R> fn)
xors
- Eithers to sequence and transformfn
- Transformation functionstatic <LT1,PT,R> Either<ListX<R>,ListX<PT>> traverseLeft(CollectionX<Either<LT1,PT>> xors, java.util.function.Function<? super LT1,? extends R> fn)
static <LT1,RT> Either<ListX<LT1>,RT> accumulate(Monoid<RT> reducer, CollectionX<Either<LT1,RT>> xors)
com.aol.cyclops2.Monoids
.
Either3<String,String,Integer> just = Either3.right(10);
Either3<String,String,Integer> none = Either3.left("none");
Either3<ListX<String>,ListX<String>,Integer> xors = Either3.accumulatePrimary(Monoids.intSum,ListX.of(just,none,Either3.right(1)));
//Either3.right(11);
xors
- Collection of Eithers to accumulate primary valuesreducer
- Reducer to accumulate resultsstatic <X,LT extends X,M extends X,RT extends X> java.util.function.Consumer<java.util.function.Consumer<? super X>> consumeAny(Either<LT,RT> either)
myEither.to(Either::consumeAny)
.accept(System.out::println);
either
- Either to consume value forstatic <X,LT extends X,M extends X,RT extends X,R> java.util.function.Function<java.util.function.Function<? super X,R>,R> applyAny(Either<LT,RT> either)
static <X,PT extends X,ST extends X,R> R visitAny(Either<ST,PT> either, java.util.function.Function<? super X,? extends R> fn)
static <X,LT extends X,RT extends X> X visitAny(java.util.function.Consumer<? super X> c, Either<LT,RT> either)
default Trampoline<RT> toTrampoline(java.util.function.Supplier<RT> defaultValue)
default Trampoline<RT> toTrampoline(RT defaultValue)
default <T2,R1,R2,R3,R> Either<LT,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>
forEach4
in interface Xor<LT,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> Either<LT,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>
forEach4
in interface Xor<LT,RT>
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> Either<LT,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>
forEach3
in interface Xor<LT,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> Either<LT,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>
forEach3
in interface Xor<LT,RT>
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> Either<LT,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>
forEach2
in interface Xor<LT,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> Either<LT,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>
forEach2
in interface Xor<LT,RT>
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 <T2,R> Either<LinkedListX<LT>,R> combineToList(Xor<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Xor
combineToList
in interface Xor<LT,RT>
app
- Value to combine withfn
- Combiner function for primary valuesdefault <T2,R> Either<LT,R> combine(Xor<? extends LT,? extends T2> app, java.util.function.BinaryOperator<LT> semigroup, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Xor
Semigroups
Primary accumulation only occurs if all phases are primary
Xor<String,String> fail1 = Xor.secondary("failed1");
Xor<LinkedListX<String>,String> result = fail1.list().combine(Xor.secondary("failed2").list(), SemigroupK.collectionConcat(),(a,b)->a+b);
//Secondary of [LinkedListX.of("failed1","failed2")))]
static <T> Either<java.lang.Throwable,T> fromPublisher(org.reactivestreams.Publisher<T> pub)
ReactiveSeq<Integer> reactiveStream = ReactiveSeq.of(1,2,3);
Either<Throwable,Integer> future = Either.fromPublisher(reactiveStream);
//Either[1]
fromPublisher
in interface Xor<LT,RT>
pub
- Publisher to construct an Either fromstatic <ST,T> Either<ST,T> fromIterable(java.lang.Iterable<T> iterable)
List<Integer> list = Arrays.asList(1,2,3);
Either<Throwable,Integer> future = Either.fromIterable(list);
//Either[1]
fromIterable
in interface Xor<LT,RT>
iterable
- Iterable to construct an Either fromstatic <ST,PT> Either<ST,PT> left(ST value)
Either.<Integer,Integer>left(10).map(i->i+1);
//Either.left[10]
Either.<Integer,Integer>left(10).swap().map(i->i+1);
//Either.right[11]
value
- to wrapstatic <ST,PT> Either<ST,PT> right(PT value)
Either.<Integer,Integer>right(10).map(i->i+1);
//Either.right[11]
value
- To construct an Either fromdefault AnyM<Witness.either,RT> anyMEither()
default Either<LT,RT> zip(java.util.function.BinaryOperator<Zippable<RT>> combiner, Zippable<RT> app)
Zippable
zip
in interface Xor<LT,RT>
zip
in interface Zippable<RT>
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> Either<LT,R> flatMapI(java.util.function.Function<? super RT,? extends java.lang.Iterable<? extends R>> mapper)
MonadicValue
Maybe.just(1).map(i->i+2).flatMapI(i->Arrays.asList(()->i*3,20);
//Maybe[9]
default <R> Either<LT,R> flatMapP(java.util.function.Function<? super RT,? extends org.reactivestreams.Publisher<? extends R>> mapper)
MonadicValue
Future.ofResult(1).map(i->i+2).flatMapP(i->Flux.just(()->i*3,20);
//Future[9]
default <R> Either<LT,R> coflatMap(java.util.function.Function<? super MonadicValue<RT>,R> mapper)
MonadicValue
Maybe.none().coflatMap(m -> m.isPresent() ? m.get() : 10);
//Maybe[10]
default Trampoline<Xor<LT,RT>> toTrampoline()
toTrampoline
in interface Xor<LT,RT>
default Trampoline<Either<LT,RT>> toEitherTrampoline()
default Either<LT,MonadicValue<RT>> nest()
MonadicValue
default Either<LT,RT> combineEager(Monoid<RT> monoid, MonadicValue<? extends RT> 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 MonadicValue<RT>
combineEager
in interface Xor<LT,RT>
default java.util.Optional<RT> toOptional()
toOptional
in interface Convertable<RT>
toOptional
in interface Xor<LT,RT>
Either<LT,RT> filter(java.util.function.Predicate<? super RT> test)
Filters
of(1,2,3).filter(i->i>2);
//[3]
Either<LT,RT> secondaryToPrimayMap(java.util.function.Function<? super LT,? extends RT> fn)
secondaryToPrimayMap
in interface Xor<LT,RT>
fn
- Function to map secondary type to primary<R> Either<R,RT> secondaryMap(java.util.function.Function<? super LT,? extends R> fn)
secondaryMap
in interface Xor<LT,RT>
fn
- Transformation function for Left types<R> Either<LT,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>
map
in interface Xor<LT,RT>
fn
- Transformation functionEither<LT,RT> secondaryPeek(java.util.function.Consumer<? super LT> action)
secondaryPeek
in interface Xor<LT,RT>
action
- Consumer to peek at the Left type valueEither<LT,RT> peek(java.util.function.Consumer<? super RT> action)
Transformable
of(1,2,3).map(System.out::println)
1
2
3
default <R> Either<LT,R> zipWith(java.lang.Iterable<java.util.function.Function<? super RT,? extends R>> fn)
default <R> Either<LT,R> zipWithS(java.util.stream.Stream<java.util.function.Function<? super RT,? extends R>> fn)
default <R> Either<LT,R> zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super RT,? extends R>> fn)
default <R> Either<LT,R> retry(java.util.function.Function<? super RT,? 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
default <U> Either<LT,org.jooq.lambda.tuple.Tuple2<RT,U>> zipP(org.reactivestreams.Publisher<? extends U> other)
default <R> Either<LT,R> retry(java.util.function.Function<? super RT,? 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
default <S,U> Either<LT,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(CyclopsCollectors.toList());
// [[1,100,'a'],[2,200,'b'],[3,300,'c']]
default <S,U,R> Either<LT,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> Either<LT,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(CyclopsCollectors.toList());
// [[1,100,'a',"hello"],[2,200,'b',"world"]]
default <T2,T3,T4,R> Either<LT,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> Either<LT,R> flatMapS(java.util.function.Function<? super RT,? extends java.util.stream.Stream<? extends R>> mapper)
Either<RT,LT> swap()
Either.left("hello")
.map(v->v+" world")
//Either.seconary["hello"]
Either.left("hello")
.swap()
.map(v->v+" world")
.swap()
//Either.seconary["hello world"]
Ior<LT,RT> toIor()
Value
default boolean isPresent()
default <ST2> Xor<ST2,RT> toXor(ST2 secondary)
Value
default boolean isSecondary()
isSecondary
in interface Xor<LT,RT>
default boolean isPrimary()
<R> R visit(java.util.function.Function<? super LT,? extends R> secondary, java.util.function.Function<? super RT,? extends R> primary)
Either.right(10)
.visit(secondary->"no", primary->"yes")
//Either["yes"]
Either.left(90)
.visit(secondary->"no", primary->"yes")
//Either["no"]
@Deprecated default <R1,R2> Either<R1,R2> mapBoth(java.util.function.Function<? super LT,? extends R1> secondary, java.util.function.Function<? super RT,? extends R2> primary)
default <R1,R2> Either<R1,R2> bimap(java.util.function.Function<? super LT,? extends R1> secondary, java.util.function.Function<? super RT,? extends R2> primary)
BiTransformable
MapX<String,Integer> map = MapXs.of("hello",2);
MapX<String,Integer> transformedMap = map.bimap(s->s+" world",i->i*4);
//["hello world",8]
default Either<LT,RT> bipeek(java.util.function.Consumer<? super LT> c1, java.util.function.Consumer<? super RT> c2)
BiTransformable
MapX<String,Integer> map = MapXs.of("hello",2);
map.bipeek(s->System.out.pritnln("key = " + s),System.out::println);
default <U1,U2> Either<U1,U2> bicast(java.lang.Class<U1> type1, java.lang.Class<U2> type2)
BiTransformable
MapX<Animal,Food> map = MapXs.of(cow,grass);
MapX<Mamaml,Vegitation> herbervoreMammals = map.bicast(Mammal.class,Vegitation.class);
default <R1,R2> Either<R1,R2> bitrampoline(java.util.function.Function<? super LT,? extends Trampoline<? extends R1>> mapper1, java.util.function.Function<? super RT,? extends Trampoline<? extends R2>> mapper2)
BiTransformable
bitrampoline
in interface BiTransformable<LT,RT>
bitrampoline
in interface Xor<LT,RT>
mapper1
- transformation function for the first typemapper2
- transformation function for the second typeRT get()
Value<LT> secondaryValue()
secondaryValue
in interface Xor<LT,RT>
LT secondaryGet()
secondaryGet
in interface Xor<LT,RT>
java.util.Optional<LT> secondaryToOptional()
secondaryToOptional
in interface Xor<LT,RT>
ReactiveSeq<LT> secondaryToStream()
secondaryToStream
in interface Xor<LT,RT>
<RT1> Either<LT,RT1> flatMap(java.util.function.Function<? super RT,? extends MonadicValue<? extends RT1>> mapper)
MonadicValue
Optional.flatMap(Function)
Eval.now(1).map(i->i+2).flatMap(i->Eval.later(()->i*3);
//Eval[9]
<LT1> Either<LT1,RT> secondaryFlatMap(java.util.function.Function<? super LT,? extends Xor<LT1,RT>> mapper)
secondaryFlatMap
in interface Xor<LT,RT>
mapper
- Flattening transformation functionEither<LT,RT> secondaryToPrimayFlatMap(java.util.function.Function<? super LT,? extends Xor<LT,RT>> fn)
secondaryToPrimayFlatMap
in interface Xor<LT,RT>
fn
- Transformation function@Deprecated void peek(java.util.function.Consumer<? super LT> stAction, java.util.function.Consumer<? super RT> ptAction)
boolean isRight()
boolean isLeft()
<T2,R> Either<LT,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
default Either<LinkedListX<LT>,RT> list()
default <T2,R> Either<LinkedListX<LT>,R> combineToList(Either<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
app
- Value to combine withfn
- Combiner function for primary valuesdefault <T2,R> Either<LT,R> combine(Either<? extends LT,? extends T2> app, java.util.function.BinaryOperator<LT> semigroup, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Semigroups
Right accumulation only occurs if all phases are primary
Either<String,String> fail1 = Either.left("failed1");
Either<LinkedListX<String>,String> result = fail1.list().combine(Either.left("failed2").list(), SemigroupK.collectionConcat(),(a,b)->a+b);
//Left of [LinkedListX.of("failed1","failed2")))]
app
- Value to combine withsemigroup
- to combine secondary typesfn
- To combine primary typesdefault <T2,R> Either<LT,R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Zippable
default <T2,R> Either<LT,R> zipP(org.reactivestreams.Publisher<? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Zippable
default <U,R> Either<LT,R> zipS(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super RT,? super U,? extends R> zipper)
Zippable
default <U> Either<LT,org.jooq.lambda.tuple.Tuple2<RT,U>> zipS(java.util.stream.Stream<? extends U> other)
Zippable
default <U> Either<LT,org.jooq.lambda.tuple.Tuple2<RT,U>> zip(java.lang.Iterable<? extends U> other)
Zippable
default <U> Either<LT,U> ofType(java.lang.Class<? extends U> type)
Filters
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
default Either<LT,RT> filterNot(java.util.function.Predicate<? super RT> fn)
Filters
of(1,2,3).filter(i->i>2);
//[1,2]
default Either<LT,RT> notNull()
Filters
of(1,2,null,4).nonNull();
//[1,2,4]
default <U> Either<LT,U> cast(java.lang.Class<? extends U> type)
Transformable
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default <R> Either<LT,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>
trampoline
in interface Xor<LT,RT>
mapper
- TCO Transformation function