LT
- Left typeRT
- Right typepublic interface LazyEither<LT,RT> extends Either<LT,RT>
public class Member{ LazyEitherteam; } Rather than public class Member{
Modifier and Type | Interface and Description |
---|---|
static class |
LazyEither.CompletableEither<ORG,RT> |
static class |
LazyEither.Lazy<ST,PT> |
static class |
LazyEither.Left<ST,PT> |
static class |
LazyEither.Right<ST,PT> |
Modifier and Type | Method and Description |
---|---|
static <LT1,RT> LazyEither<LT1,RT> |
accumulate(Monoid<RT> reducer,
java.lang.Iterable<LazyEither<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.oath.cyclops.Monoids . |
static <X,LT extends X,M extends X,RT extends X,R> |
applyAny(LazyEither<LT,RT> either) |
default int |
arity() |
static <RT> LazyEither<java.lang.Throwable,RT> |
async(java.util.concurrent.Executor ex,
java.util.function.Supplier<RT> s) |
default <R1,R2> LazyEither<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 LazyEither<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 <T2,R> LazyEither<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 left values with the provided BinaryOperator / Semigroup
Semigroups
Right accumulation only occurs if all phases are right |
default <T2,R> LazyEither<LT,R> |
combine(LazyEither<? extends LT,? extends T2> app,
java.util.function.BinaryOperator<LT> semigroup,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Accumulate left values with the provided BinaryOperator / Semigroup
Semigroups
Right accumulation only occurs if all phases are right |
default <T2,R> LazyEither<LazySeq<LT>,R> |
combineToLazySeq(Either<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Accumulate lefts into a LazySeq (extended Persistent List) and Right with the supplied combiner function
Right accumulation only occurs if all phases are right
|
default <T2,R> LazyEither<LazySeq<LT>,R> |
combineToList(LazyEither<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Accumulate secondarys into a LazySeq (extended Persistent List) and Right with the supplied combiner function
Right accumulation only occurs if all phases are right
|
static <X,LT extends X,M extends X,RT extends X> |
consumeAny(LazyEither<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> LazyEither.CompletableEither<RT,RT> |
either()
Create a reactive CompletableEither
|
Maybe<RT> |
filter(java.util.function.Predicate<? super RT> test)
Keep only elements for which the supplied predicates hold
e.g.
|
default LazyEither<LT,RT> |
filter(java.util.function.Predicate<? super RT> test,
java.util.function.Function<? super RT,? extends LT> rightToLeft) |
<RT1> LazyEither<LT,RT1> |
flatMap(java.util.function.Function<? super RT,? extends Either<? extends LT,? extends RT1>> mapper) |
<LT1> LazyEither<LT1,RT> |
flatMapLeft(java.util.function.Function<? super LT,? extends Either<LT1,RT>> mapper)
Perform a flatMap operation on the Left type
|
LazyEither<LT,RT> |
flatMapLeftToRight(java.util.function.Function<? super LT,? extends Either<LT,RT>> fn)
A flatMap operation that keeps the Left and Right types the same
|
<R> R |
fold(java.util.function.Function<? super LT,? extends R> secondary,
java.util.function.Function<? super RT,? extends R> primary)
Visitor pattern for this Ior.
|
default <R1,R> Either<LT,R> |
forEach2(java.util.function.Function<? super RT,? extends Either<LT,R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends R> yieldingFunction) |
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super RT,? extends Either<LT,R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends Either<LT,R2>> value2,
Function3<? super RT,? super R1,? super R2,? extends R> yieldingFunction) |
default <T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super RT,? extends Either<LT,R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends Either<LT,R2>> value2,
Function3<? super RT,? super R1,? super R2,? extends Either<LT,R3>> value3,
Function4<? super RT,? super R1,? super R2,? super R3,? extends R> yieldingFunction) |
static <ST,PT> LazyEither<ST,PT> |
fromEither(Either<ST,PT> xor) |
static <T> LazyEither<java.lang.Throwable,T> |
fromFuture(Future<T> future) |
static <ST,T> LazyEither<ST,T> |
fromIterable(java.lang.Iterable<T> iterable,
T alt)
Construct a Right Either from the supplied Iterable
|
static <LT,RT> LazyEither<LT,RT> |
fromLazy(Eval<LazyEither<LT,RT>> lazy) |
static <T> LazyEither<java.lang.Throwable,T> |
fromPublisher(org.reactivestreams.Publisher<T> pub)
Lazily construct a Right Either from the supplied publisher
|
Option<RT> |
get() |
Option<LT> |
getLeft() |
boolean |
isLeft() |
default boolean |
isPresent() |
boolean |
isRight() |
default LazyEither<LazySeq<LT>,RT> |
lazySeq() |
static <ST,PT> LazyEither<ST,PT> |
left(ST value)
Create an instance of the left type.
|
static <LT,B,RT> LazyEither<LT,RT> |
leftEval(Eval<LT> left) |
ReactiveSeq<LT> |
leftToStream() |
<R> LazyEither<LT,R> |
map(java.util.function.Function<? super RT,? extends R> fn)
Transform this functor using the supplied transformation function
|
<R> LazyEither<R,RT> |
mapLeft(java.util.function.Function<? super LT,? extends R> fn)
Always transform the Left type of this Either if it is present using the provided transformation function
|
LazyEither<LT,RT> |
mapLeftToRight(java.util.function.Function<? super LT,? extends RT> fn)
If this Either contains the Left type, transform it's value so that it contains the Right type
|
static <ST,PT> LazyEither<ST,PT> |
narrow(LazyEither<? extends ST,? extends PT> broad) |
static <ST,T> LazyEither<ST,T> |
narrowK(Higher<Higher<DataWitness.either,ST>,T> xor) |
static <ST,T> LazyEither<ST,T> |
narrowK2(Higher2<DataWitness.either,ST,T> xor) |
default LazyEither<LT,Either<LT,RT>> |
nest() |
LazyEither<LT,RT> |
peek(java.util.function.Consumer<? super RT> action)
Peek at the current value of this Transformable, without transforming it
|
LazyEither<LT,RT> |
peekLeft(java.util.function.Consumer<? super LT> action)
Peek at the Left type value if present
|
static <ST,PT> LazyEither<ST,PT> |
right(PT value)
Create an instance of the right type.
|
static <LT,B,RT> LazyEither<LT,RT> |
rightEval(Eval<RT> right) |
static <L,T> LazyEither<L,ReactiveSeq<T>> |
sequence(ReactiveSeq<? extends LazyEither<L,T>> stream) |
static <LT1,PT> LazyEither<ReactiveSeq<LT1>,PT> |
sequenceLeft(java.lang.Iterable<LazyEither<LT1,PT>> xors) |
static <LT1,PT> LazyEither<LT1,ReactiveSeq<PT>> |
sequenceRight(java.lang.Iterable<LazyEither<LT1,PT>> xors)
Turn an IterableX of Eithers into a single Either with Lists of values.
|
LazyEither<RT,LT> |
swap()
Swap types so operations directly affect the current (pre-swap) Left type
|
static <L,T,R> LazyEither<L,R> |
tailRec(T initial,
java.util.function.Function<? super T,? extends LazyEither<L,? extends Either<T,R>>> fn) |
default Either<LT,RT> |
toEither() |
default <ST2> Either<ST2,RT> |
toEither(ST2 secondary)
Convert to an Xor where the left value will be used if no right value is present
|
default Trampoline<LazyEither<LT,RT>> |
toEitherTrampoline() |
Ior<LT,RT> |
toIor() |
default Trampoline<Either<LT,RT>> |
toTrampoline() |
default Trampoline<RT> |
toTrampoline(RT defaultValue) |
default Trampoline<RT> |
toTrampoline(java.util.function.Supplier<RT> defaultValue) |
static <L,T,R> LazyEither<L,ReactiveSeq<R>> |
traverse(java.util.function.Function<? super T,? extends R> fn,
ReactiveSeq<LazyEither<L,T>> stream) |
static <LT1,PT,R> LazyEither<ReactiveSeq<R>,PT> |
traverseLeft(java.lang.Iterable<LazyEither<LT1,PT>> xors,
java.util.function.Function<? super LT1,? extends R> fn) |
static <LT1,PT,R> LazyEither<LT1,ReactiveSeq<R>> |
traverseRight(java.lang.Iterable<LazyEither<LT1,PT>> xors,
java.util.function.Function<? super PT,? extends R> fn)
TraverseOps a Collection of Either producting an Either3 with a Seq, applying the transformation function to every
element in the list
|
default <T> LazyEither<LT,T> |
unit(T unit) |
static <X,LT extends X,RT extends X> |
visitAny(java.util.function.Consumer<? super X> c,
LazyEither<LT,RT> either) |
static <X,PT extends X,ST extends X,R> |
visitAny(LazyEither<ST,PT> either,
java.util.function.Function<? super X,? extends R> fn) |
default <T2,R> LazyEither<LT,R> |
zip(Either<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn) |
default <T2,R> LazyEither<LT,R> |
zip(Ior<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn) |
accumulateLeft, accumulateLeft, accumulateLeft, accumulateRight, accumulateRight, accumulateRight, applyAny, combineToVector, consumeAny, filterNot, fromIterable, leftOrElse, nestedEval, notNull, ofType, recover, recover, recoverWith, sequence, sequenceLeft, sequenceRight, tailRec, traverse, visitAny, visitAny, widen
orElseUse, orElseUse
asSupplier, collect, fold, forEach, generate, iterate, iterator, mkString, newSubscriber, nonEmptyList, nonEmptyListGet, orElse, orElseGet, print, print, printErr, printOut, stream, subscribe, toLazyEither, toLeft, toMaybe, toOption, toOptional, toRight, toTry, toTry, toTry, transform
static <ST,T> LazyEither<ST,T> narrowK2(Higher2<DataWitness.either,ST,T> xor)
static <ST,T> LazyEither<ST,T> narrowK(Higher<Higher<DataWitness.either,ST>,T> xor)
static <L,T,R> LazyEither<L,R> tailRec(T initial, java.util.function.Function<? super T,? extends LazyEither<L,? extends Either<T,R>>> fn)
static <RT> LazyEither<java.lang.Throwable,RT> async(java.util.concurrent.Executor ex, java.util.function.Supplier<RT> s)
static <RT> LazyEither.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 <ST,PT> LazyEither<ST,PT> fromEither(Either<ST,PT> xor)
static <LT,RT> LazyEither<LT,RT> fromLazy(Eval<LazyEither<LT,RT>> lazy)
static <T> LazyEither<java.lang.Throwable,T> fromFuture(Future<T> future)
static <LT1,PT> LazyEither<LT1,ReactiveSeq<PT>> sequenceRight(java.lang.Iterable<LazyEither<LT1,PT>> xors)
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<Seq<String>,Seq<Integer>> xors =Either.sequence(Seq.of(just,none,Either.right(1)));
//Eitehr.right(Seq.of(10,1)));
xors
- Either to sequencestatic <LT1,PT> LazyEither<ReactiveSeq<LT1>,PT> sequenceLeft(java.lang.Iterable<LazyEither<LT1,PT>> xors)
static <L,T> LazyEither<L,ReactiveSeq<T>> sequence(ReactiveSeq<? extends LazyEither<L,T>> stream)
static <L,T,R> LazyEither<L,ReactiveSeq<R>> traverse(java.util.function.Function<? super T,? extends R> fn, ReactiveSeq<LazyEither<L,T>> stream)
static <LT1,PT,R> LazyEither<LT1,ReactiveSeq<R>> traverseRight(java.lang.Iterable<LazyEither<LT1,PT>> xors, java.util.function.Function<? super PT,? extends R> fn)
xors
- Eithers to sequence and transformfn
- Transformation functionstatic <LT1,PT,R> LazyEither<ReactiveSeq<R>,PT> traverseLeft(java.lang.Iterable<LazyEither<LT1,PT>> xors, java.util.function.Function<? super LT1,? extends R> fn)
static <LT1,RT> LazyEither<LT1,RT> accumulate(Monoid<RT> reducer, java.lang.Iterable<LazyEither<LT1,RT>> xors)
com.oath.cyclops.Monoids
.
Either3<String,String,Integer> just = Either3.right(10);
Either3<String,String,Integer> none = Either3.left("none");
Either3<Seq<String>,Seq<String>,Integer> xors = Either3.accumulateRight(Monoids.intSum,Seq.of(just,none,Either3.right(1)));
//Either3.right(11);
xors
- Collection of Eithers to accumulate right valuesreducer
- Reducer to accumulate resultsstatic <LT,B,RT> LazyEither<LT,RT> rightEval(Eval<RT> right)
static <LT,B,RT> LazyEither<LT,RT> leftEval(Eval<LT> left)
static <X,LT extends X,M extends X,RT extends X> java.util.function.Consumer<java.util.function.Consumer<? super X>> consumeAny(LazyEither<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(LazyEither<LT,RT> either)
static <X,PT extends X,ST extends X,R> R visitAny(LazyEither<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, LazyEither<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> LazyEither<LT,R> forEach4(java.util.function.Function<? super RT,? extends Either<LT,R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends Either<LT,R2>> value2, Function3<? super RT,? super R1,? super R2,? extends Either<LT,R3>> value3, Function4<? super RT,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
default <T2,R1,R2,R> Either<LT,R> forEach3(java.util.function.Function<? super RT,? extends Either<LT,R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends Either<LT,R2>> value2, Function3<? super RT,? super R1,? super R2,? extends R> yieldingFunction)
default <R1,R> Either<LT,R> forEach2(java.util.function.Function<? super RT,? extends Either<LT,R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends R> yieldingFunction)
default <T2,R> LazyEither<LazySeq<LT>,R> combineToLazySeq(Either<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
Either
combineToLazySeq
in interface Either<LT,RT>
app
- Value to combine withfn
- Combiner function for right valuesdefault <T2,R> LazyEither<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)
Either
Semigroups
Right accumulation only occurs if all phases are right
Either<String,String> fail1 = Either.left("failed1");
Either<LazySeq<String>,String> result = fail1.list().combine(Either.left("failed2").list(), SemigroupK.collectionConcat(),(a,b)->a+b);
//Left of [LazySeq.of("failed1","failed2")))]
static <T> LazyEither<java.lang.Throwable,T> fromPublisher(org.reactivestreams.Publisher<T> pub)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
Either<Throwable,Integer> future = Either.fromPublisher(stream);
//Either[1]
fromPublisher
in interface Either<LT,RT>
pub
- Publisher to construct an Either fromstatic <ST,T> LazyEither<ST,T> fromIterable(java.lang.Iterable<T> iterable, T alt)
List<Integer> list = Arrays.asList(1,2,3);
Either<Throwable,Integer> future = Either.fromIterable(list);
//Either[1]
iterable
- Iterable to construct an Either fromstatic <ST,PT> LazyEither<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]
static <ST,PT> LazyEither<ST,PT> right(PT value)
Either.<Integer,Integer>right(10).map(i->i+1);
//Either.right[11]
default Trampoline<Either<LT,RT>> toTrampoline()
toTrampoline
in interface Either<LT,RT>
default Trampoline<LazyEither<LT,RT>> toEitherTrampoline()
default <T2,R> LazyEither<LT,R> zip(Ior<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
default <T2,R> LazyEither<LT,R> zip(Either<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
default <T> LazyEither<LT,T> unit(T unit)
Maybe<RT> filter(java.util.function.Predicate<? super RT> test)
Filters
of(1,2,3).filter(i->i>2);
//[3]
default LazyEither<LT,RT> filter(java.util.function.Predicate<? super RT> test, java.util.function.Function<? super RT,? extends LT> rightToLeft)
LazyEither<LT,RT> mapLeftToRight(java.util.function.Function<? super LT,? extends RT> fn)
mapLeftToRight
in interface Either<LT,RT>
fn
- Function to transform left type to right<R> LazyEither<R,RT> mapLeft(java.util.function.Function<? super LT,? extends R> fn)
<R> LazyEither<LT,R> map(java.util.function.Function<? super RT,? extends R> fn)
Transformable
of(1,2,3).map(i->i*2)
//[2,4,6]
LazyEither<LT,RT> peekLeft(java.util.function.Consumer<? super LT> action)
LazyEither<LT,RT> peek(java.util.function.Consumer<? super RT> action)
Transformable
of(1,2,3).map(System.out::println)
1
2
3
LazyEither<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"]
default boolean isPresent()
default <ST2> Either<ST2,RT> toEither(ST2 secondary)
Value
<R> R fold(java.util.function.Function<? super LT,? extends R> secondary, java.util.function.Function<? super RT,? extends R> primary)
Either.right(10)
.visit(left->"no", right->"yes")
//Either["yes"]
Either.left(90)
.visit(left->"no", right->"yes")
//Either["no"]
default <R1,R2> LazyEither<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 LazyEither<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);
ReactiveSeq<LT> leftToStream()
leftToStream
in interface Either<LT,RT>
<RT1> LazyEither<LT,RT1> flatMap(java.util.function.Function<? super RT,? extends Either<? extends LT,? extends RT1>> mapper)
<LT1> LazyEither<LT1,RT> flatMapLeft(java.util.function.Function<? super LT,? extends Either<LT1,RT>> mapper)
flatMapLeft
in interface Either<LT,RT>
mapper
- Flattening transformation functionLazyEither<LT,RT> flatMapLeftToRight(java.util.function.Function<? super LT,? extends Either<LT,RT>> fn)
flatMapLeftToRight
in interface Either<LT,RT>
fn
- Transformation functionboolean isRight()
boolean isLeft()
default LazyEither<LazySeq<LT>,RT> lazySeq()
default <T2,R> LazyEither<LazySeq<LT>,R> combineToList(LazyEither<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
app
- Value to combine withfn
- Combiner function for right valuesdefault <T2,R> LazyEither<LT,R> combine(LazyEither<? 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 right
Either<String,String> fail1 = Either.left("failed1");
Either<LazySeq<String>,String> result = fail1.list().combine(Either.left("failed2").list(), SemigroupK.collectionConcat(),(a,b)->a+b);
//Left of [LazySeq.of("failed1","failed2")))]
app
- Value to combine withsemigroup
- to combine left typesfn
- To combine right typesstatic <ST,PT> LazyEither<ST,PT> narrow(LazyEither<? extends ST,? extends PT> broad)