LT
- Left typeRT
- Right typepublic interface Either<LT,RT> extends To<Either<LT,RT>>, BiTransformable<LT,RT>, Sealed2<LT,RT>, Value<RT>, OrElseValue<RT,Either<LT,RT>>, Unit<RT>, Transformable<RT>, Filters<RT>, java.io.Serializable, Higher2<DataWitness.either,LT,RT>
public class Member{ Eitherteam; } Rather than public class Member{
Modifier and Type | Interface and Description |
---|---|
static class |
Either.Instances |
static class |
Either.Left<L,R> |
static class |
Either.Right<L,RT> |
Modifier and Type | Method and Description |
---|---|
default Either<LT,RT> |
accumulate(Either<LT,RT> next,
Semigroup<RT> sg) |
default Either<LT,RT> |
accumulate(Semigroup<LT> sg,
Either<LT,RT>... values) |
default Either<LT,RT> |
accumulate(Semigroup<LT> sg,
Either<LT,RT> next) |
static <LT,RT,R> Either<RT,R> |
accumulateLeft(IterableX<Either<LT,RT>> xors,
Reducer<R,LT> reducer)
Accumulate the result of the Left types in the Collection of Eithers provided using the supplied Reducer
cyclops2.Reducers . |
static <ST,PT,R> Either<PT,R> |
accumulateLeft(IterableX<Either<ST,PT>> xors,
java.util.function.Function<? super ST,R> mapper,
Monoid<R> reducer)
Accumulate the results only from those Eithers which have a Left type present, using the supplied mapping function to
convert the data from each Either before reducing them 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)
cyclops2.Monoids .. |
static <ST,PT> Either<PT,ST> |
accumulateLeft(Monoid<ST> reducer,
IterableX<Either<ST,PT>> xors)
Accumulate the results only from those Eithers which have a Left 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)
cyclops2.Monoids . |
static <LT,RT,R> Either<LT,R> |
accumulateRight(IterableX<Either<LT,RT>> xors,
Reducer<R,RT> reducer)
Accumulate the result of the Right types in the Collection of Eithers provided using the supplied Reducer
cyclops2.Reducers . |
static <ST,PT,R> Either<ST,R> |
accumulateRight(IterableX<Either<ST,PT>> xors,
java.util.function.Function<? super PT,R> mapper,
Monoid<R> reducer)
Accumulate the results only from those Iors which have a Right type present, using the supplied mapping function to
convert the data from each Either before reducing them 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)
cyclops2.Monoids .. |
static <ST,PT> Either<ST,PT> |
accumulateRight(Monoid<PT> reducer,
IterableX<Either<ST,PT>> xors)
Accumulate the results only from those Eithers 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)
cyclops2.Monoids . |
default Either<LT,RT> |
accumulateRight(Semigroup<RT> sg,
Either<LT,RT>... values) |
default Active<Higher<DataWitness.either,LT>,RT> |
allTypeclasses() |
static <X,LT extends X,M extends X,RT extends X,R> |
applyAny(Either<LT,RT> either) |
default <R1,R2> Either<R1,R2> |
bimap(java.util.function.Function<? super LT,? extends R1> left,
java.util.function.Function<? super RT,? extends R2> right)
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 <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 left values with the provided BinaryOperator / Semigroup
Semigroups
Right accumulation only occurs if all phases are right |
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 lefts into a LinkedListX (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(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)
|
default <W1> Coproduct<W1,Higher<DataWitness.either,LT>,RT> |
coproduct(InstanceDefinitions<W1> def2) |
Option<RT> |
filter(java.util.function.Predicate<? super RT> test)
Keep only elements for which the supplied predicates hold
e.g.
|
Either<LT,RT> |
filter(java.util.function.Predicate<? super RT> test,
java.util.function.Function<? super RT,? extends LT> rightToLeft) |
default Option<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 Either<? extends LT,? extends RT1>> mapper) |
<LT1> Either<LT1,RT> |
flatMapLeft(java.util.function.Function<? super LT,? extends Either<LT1,RT>> mapper)
Perform a flatMap operation on the Left type
|
Either<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
|
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,T> Either<ST,T> |
fromIterable(java.lang.Iterable<T> iterable)
Construct a Right Either from the supplied Iterable
|
static <T> Either<java.lang.Throwable,T> |
fromPublisher(org.reactivestreams.Publisher<T> pub)
Construct a Right Either from the supplied publisher
|
Option<RT> |
get() |
Option<LT> |
getLeft() |
boolean |
isLeft() |
default boolean |
isPresent() |
boolean |
isRight() |
static <L,T> Cokleisli<Higher<DataWitness.either,L>,T,Either<L,T>> |
kindCokleisli() |
static <L,T> Kleisli<Higher<DataWitness.either,L>,Either<L,T>,T> |
kindKleisli() |
static <ST,PT> Either<ST,PT> |
left(ST value)
Create an instance of the left type.
|
LT |
leftOrElse(LT alt) |
ReactiveSeq<LT> |
leftToStream() |
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
|
<R> Either<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
|
Either<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
|
default <W2,R> Nested<Higher<DataWitness.either,LT>,W2,R> |
mapM(java.util.function.Function<? super RT,? extends Higher<W2,R>> fn,
InstanceDefinitions<W2> defs) |
static <ST,T> Either<ST,T> |
narrowK(Higher<Higher<DataWitness.either,ST>,T> xor) |
static <ST,T> Either<ST,T> |
narrowK2(Higher2<DataWitness.either,ST,T> xor) |
default Either<LT,Either<LT,RT>> |
nest() |
static <W1,ST,PT> Nested<Higher<DataWitness.either,ST>,W1,PT> |
nested(Either<ST,Higher<W1,PT>> nested,
InstanceDefinitions<W1> def2) |
default Eval<Either<LT,RT>> |
nestedEval() |
default Option<RT> |
notNull()
Filter elements retaining only values which are not null
|
default <U> Option<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
|
Either<LT,RT> |
peekLeft(java.util.function.Consumer<? super LT> action)
Peek at the Left type value if present
|
default <W1> Product<Higher<DataWitness.either,LT>,W1,RT> |
product(Active<W1,RT> active) |
Either<LT,RT> |
recover(RT value) |
Either<LT,RT> |
recover(java.util.function.Supplier<? extends RT> value) |
Either<LT,RT> |
recoverWith(java.util.function.Supplier<? extends Either<LT,RT>> fn) |
static <ST,PT> Either<ST,PT> |
right(PT value)
Create an instance of the right type.
|
static <L,T> Either<L,java.util.stream.Stream<T>> |
sequence(java.util.stream.Stream<? extends Either<L,T>> stream) |
static <ST,PT> Either<PT,ReactiveSeq<ST>> |
sequenceLeft(IterableX<Either<ST,PT>> xors)
Turn a Collection of Eithers into a single Either with Lists of values.
|
static <ST,PT> Either<ST,ReactiveSeq<PT>> |
sequenceRight(IterableX<Either<ST,PT>> eithers)
Turn a Collection of Eithers into a single 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 Either<T,R>>> fn) |
default <ST2> Either<ST2,RT> |
toEither(ST2 left)
Convert to an Xor where the left value will be used if no right value is present
|
Ior<LT,RT> |
toIor() |
default Trampoline<Either<LT,RT>> |
toTrampoline() |
default <R> Either<LT,R> |
trampoline(java.util.function.Function<? super RT,? extends Trampoline<? extends R>> mapper)
Performs a transform operation that can call a recursive method without running out of stack space
|
static <L,T,R> Either<L,java.util.stream.Stream<R>> |
traverse(java.util.function.Function<? super T,? extends R> fn,
java.util.stream.Stream<Either<L,T>> stream) |
default <T> Either<LT,T> |
unit(T unit) |
<R> R |
visit(java.util.function.Function<? super LT,? extends R> left,
java.util.function.Function<? super RT,? extends R> right)
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) |
static <L,T> Higher<Higher<DataWitness.either,L>,T> |
widen(Either<L,T> narrow) |
default <T2,R> Either<LT,R> |
zip(Either<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn) |
default <T2,R> Either<LT,R> |
zip(Ior<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn) |
orElseUse
asSupplier, collect, fold, forEach, generate, iterate, iterator, mkString, newSubscriber, orElse, orElseGet, print, print, printErr, printOut, stream, subscribe, toLazyEither, toLeft, toMaybe, toOption, toOptional, toRight, toTry, toTry, toTry, transform
retry, retry
static <L,T,R> Either<L,R> tailRec(T initial, java.util.function.Function<? super T,? extends Either<L,? extends Either<T,R>>> fn)
static <L,T> Kleisli<Higher<DataWitness.either,L>,Either<L,T>,T> kindKleisli()
static <L,T> Higher<Higher<DataWitness.either,L>,T> widen(Either<L,T> narrow)
static <L,T> Cokleisli<Higher<DataWitness.either,L>,T,Either<L,T>> kindCokleisli()
static <W1,ST,PT> Nested<Higher<DataWitness.either,ST>,W1,PT> nested(Either<ST,Higher<W1,PT>> nested, InstanceDefinitions<W1> def2)
default <W1> Coproduct<W1,Higher<DataWitness.either,LT>,RT> coproduct(InstanceDefinitions<W1> def2)
default Active<Higher<DataWitness.either,LT>,RT> allTypeclasses()
default <W2,R> Nested<Higher<DataWitness.either,LT>,W2,R> mapM(java.util.function.Function<? super RT,? extends Higher<W2,R>> fn, InstanceDefinitions<W2> defs)
static <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)
static <ST,T> Either<ST,T> narrowK2(Higher2<DataWitness.either,ST,T> xor)
static <ST,T> Either<ST,T> narrowK(Higher<Higher<DataWitness.either,ST>,T> xor)
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]
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.fromPublisher(reactiveStream);
//Either[1]
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 <T2,R1,R2,R3,R> Either<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)
Option<RT> filter(java.util.function.Predicate<? super RT> test)
Filters
of(1,2,3).filter(i->i>2);
//[3]
Either<LT,RT> filter(java.util.function.Predicate<? super RT> test, java.util.function.Function<? super RT,? extends LT> rightToLeft)
Either<LT,RT> mapLeftToRight(java.util.function.Function<? super LT,? extends RT> fn)
fn
- Function to transform left type to right<R> Either<R,RT> mapLeft(java.util.function.Function<? super LT,? extends R> fn)
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 Transformable<RT>
fn
- Transformation functionEither<LT,RT> peekLeft(java.util.function.Consumer<? super LT> action)
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
peek
in interface Transformable<RT>
action
- Consumer that recieves each element from this TransformableEither<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 <ST2> Either<ST2,RT> toEither(ST2 left)
Value
static <ST,PT> Either<PT,ReactiveSeq<ST>> sequenceLeft(IterableX<Either<ST,PT>> xors)
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<ListX<Integer>,ListX<String>> xors =Either.sequenceLeft(ListX.of(just,none,Either.right(1)));
//Either.right(ListX.of("none")))
xors
- Eithers to sequencestatic <L,T> Either<L,java.util.stream.Stream<T>> sequence(java.util.stream.Stream<? extends Either<L,T>> stream)
static <L,T,R> Either<L,java.util.stream.Stream<R>> traverse(java.util.function.Function<? super T,? extends R> fn, java.util.stream.Stream<Either<L,T>> stream)
static <LT,RT,R> Either<RT,R> accumulateLeft(IterableX<Either<LT,RT>> xors, Reducer<R,LT> reducer)
cyclops2.Reducers
.
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<?,PersistentSetX<String>> xors = Either.accumulateLeft(ListX.of(just,none,Either.right(1)),Reducers.<String>toPersistentSetX());
//Either.right(PersistentSetX.of("none"))));
xors
- Collection of Iors to accumulate left valuesreducer
- Reducer to accumulate resultsstatic <ST,PT,R> Either<PT,R> accumulateLeft(IterableX<Either<ST,PT>> xors, java.util.function.Function<? super ST,R> mapper, Monoid<R> reducer)
cyclops2.Monoids
..
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<?,String> xors = Either.accumulateLeft(ListX.of(just,none,Either.left("1")),i->""+i,Monoids.stringConcat);
//Either.right("none1")
xors
- Collection of Iors to accumulate left valuesmapper
- Mapping function to be applied to the result of each Iorreducer
- Semigroup to combine values from each Iorstatic <ST,PT> Either<ST,ReactiveSeq<PT>> sequenceRight(IterableX<Either<ST,PT>> eithers)
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<ListX<String>,ListX<Integer>> xors =Either.sequenceRight(ListX.of(just,none,Either.right(1)));
//Either.right(ListX.of(10,1)));
eithers
- Eithers to sequencestatic <LT,RT,R> Either<LT,R> accumulateRight(IterableX<Either<LT,RT>> xors, Reducer<R,RT> reducer)
cyclops2.Reducers
.
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<?,PersistentSetX<Integer>> xors =Either.accumulateRight(ListX.of(just,none,Either.right(1)),Reducers.toPersistentSetX());
//Either.right(PersistentSetX.of(10,1))));
xors
- Collection of Iors to accumulate right valuesreducer
- Reducer to accumulate resultsstatic <ST,PT,R> Either<ST,R> accumulateRight(IterableX<Either<ST,PT>> xors, java.util.function.Function<? super PT,R> mapper, Monoid<R> reducer)
cyclops2.Monoids
..
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<?,String> iors = Either.accumulateRight(ListX.of(just,none,Either.right(1)),i->""+i,Monoids.stringConcat);
//Either.right("101"));
xors
- Collection of Iors to accumulate right valuesmapper
- Mapping function to be applied to the result of each Iorreducer
- Reducer to accumulate resultsstatic <ST,PT> Either<ST,PT> accumulateRight(Monoid<PT> reducer, IterableX<Either<ST,PT>> xors)
cyclops2.Monoids
.
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<?,Integer> xors XIor.accumulateRight(Monoids.intSum,ListX.of(just,none,Ior.right(1)));
//Ior.right(11);
xors
- Collection of Eithers to accumulate right valuesreducer
- Reducer to accumulate resultsstatic <ST,PT> Either<PT,ST> accumulateLeft(Monoid<ST> reducer, IterableX<Either<ST,PT>> xors)
cyclops2.Monoids
.
Either.accumulateLeft(ListX.of(Either.left("failed1"),
Either.left("failed2"),
Either.right("success")),
SemigroupK.stringConcat)
//Eithers.Right[failed1failed2]
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<?,Integer> iors = Either.accumulateLeft(Monoids.intSum,ListX.of(Either.both(2, "boo!"),Either.left(1)));
//Either.right(3); 2+1
xors
- Collection of Eithers to accumulate left valuesreducer
- Semigroup to combine values from each Either<R> R visit(java.util.function.Function<? super LT,? extends R> left, java.util.function.Function<? super RT,? extends R> right)
Either.right(10)
.visit(left->"no", right->"yes")
//Either["yes"]
Either.left(90)
.visit(left->"no", right->"yes")
//Either["no"]
left
- Function to execute if this is a Left Eitherright
- Function to execute if this is a Right Iordefault <R1,R2> Either<R1,R2> bimap(java.util.function.Function<? super LT,? extends R1> left, java.util.function.Function<? super RT,? extends R2> right)
BiTransformable
MapX<String,Integer> map = MapXs.of("hello",2);
MapX<String,Integer> transformedMap = map.bimap(s->s+" world",i->i*4);
//["hello world",8]
bimap
in interface BiTransformable<LT,RT>
left
- transformation function for the first typeright
- transformation function for the second typedefault 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);
bipeek
in interface BiTransformable<LT,RT>
c1
- consumer for the first typec2
- consumer for the second typedefault <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>
mapper1
- transformation function for the first typemapper2
- transformation function for the second typeReactiveSeq<LT> leftToStream()
<RT1> Either<LT,RT1> flatMap(java.util.function.Function<? super RT,? extends Either<? extends LT,? extends RT1>> mapper)
<LT1> Either<LT1,RT> flatMapLeft(java.util.function.Function<? super LT,? extends Either<LT1,RT>> mapper)
mapper
- Flattening transformation functionEither<LT,RT> flatMapLeftToRight(java.util.function.Function<? super LT,? extends Either<LT,RT>> fn)
fn
- Transformation function@Deprecated void peek(java.util.function.Consumer<? super LT> stAction, java.util.function.Consumer<? super RT> ptAction)
boolean isRight()
boolean isLeft()
default <T2,R> Either<LT,R> zip(Ior<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
default <T2,R> Either<LT,R> zip(Either<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
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 right 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 right
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 left typesfn
- To combine right typesdefault <U> Option<U> ofType(java.lang.Class<? extends U> type)
Filters
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
default Option<RT> filterNot(java.util.function.Predicate<? super RT> fn)
Filters
of(1,2,3).filter(i->i>2);
//[1,2]
default Option<RT> notNull()
Filters
of(1,2,null,4).nonNull();
//[1,2,4]
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>
mapper
- TCO Transformation functiondefault Trampoline<Either<LT,RT>> toTrampoline()