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.Left<L,R> |
static class |
Either.Right<L,RT> |
Modifier and Type | Method and Description |
---|---|
static <LT,RT,R> Either<RT,R> |
accumulateLeft(java.lang.Iterable<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(java.lang.Iterable<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,
java.lang.Iterable<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(java.lang.Iterable<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(java.lang.Iterable<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,
java.lang.Iterable<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 . |
static <X,LT extends X,M extends X,RT extends X,R> |
applyAny(Either<LT,RT> either) |
default int |
arity() |
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 <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<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> Either<Vector<LT>,R> |
combineToVector(Either<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn) |
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)
|
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
|
<R> R |
fold(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,PT extends X,ST extends X,R> |
foldAny(Either<ST,PT> either,
java.util.function.Function<? super X,? extends R> fn) |
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() |
default Either<LazySeq<LT>,RT> |
lazySeq() |
static <ST,PT> Either<ST,PT> |
left(ST value)
Create an instance of the left type.
|
LT |
leftOrElse(LT alt) |
ReactiveSeq<LT> |
leftToStream() |
<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
|
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() |
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 stream that are of a given type.
|
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
|
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(java.lang.Iterable<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(java.lang.Iterable<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() |
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) |
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)
Deprecated.
|
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, orElseUse
asSupplier, collect, fold, forEach, generate, iterate, iterator, mkString, nonEmptyList, nonEmptyListGet, orElse, orElseGet, print, print, printErr, printOut, stream, subscribe, toLazyEither, toLeft, toMaybe, toOption, toOptional, toRight, toTry, toTry, toTry
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> Higher<Higher<DataWitness.either,L>,T> widen(Either<L,T> narrow)
default int arity()
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)
@Deprecated 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,PT extends X,ST extends X,R> R foldAny(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> stream = ReactiveSeq.of(1,2,3);
Either<Throwable,Integer> future = Either.fromPublisher(stream);
//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(stream);
//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(java.lang.Iterable<Either<ST,PT>> xors)
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<Seq<Integer>,Seq<String>> xors =Either.sequenceLeft(Seq.of(just,none,Either.right(1)));
//Either.right(Seq.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(java.lang.Iterable<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(Seq.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(java.lang.Iterable<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(Seq.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(java.lang.Iterable<Either<ST,PT>> eithers)
Either<String,Integer> just = Either.right(10);
Either<String,Integer> none = Either.left("none");
Either<Seq<String>,Seq<Integer>> xors =Either.sequenceRight(Seq.of(just,none,Either.right(1)));
//Either.right(Seq.of(10,1)));
eithers
- Eithers to sequencestatic <LT,RT,R> Either<LT,R> accumulateRight(java.lang.Iterable<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(Seq.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(java.lang.Iterable<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(Seq.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, java.lang.Iterable<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,Seq.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, java.lang.Iterable<Either<ST,PT>> xors)
cyclops2.Monoids
.
Either.accumulateLeft(Seq.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,Seq.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 fold(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"]
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)
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 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 functionboolean 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 <T2,R> Either<LazySeq<LT>,R> combineToLazySeq(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<Vector<LT>,R> combineToVector(Either<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
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)
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 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 Trampoline<Either<LT,RT>> toTrampoline()