public abstract class Either<A,B>
extends java.lang.Object
Either type represents a value of one of two possible types (a disjoint union).
The data constructors; Left and Right represent the two possible
values. The Either type is often used as an alternative to
scala.Option where Left represents failure (by convention) and
Right is akin to Some.| Modifier and Type | Class and Description |
|---|---|
static class |
Either.LeftProjection<A,B>
A left projection of an either value.
|
static class |
Either.RightProjection<A,B>
A right projection of an either value.
|
| Modifier and Type | Method and Description |
|---|---|
<X,Y> Either<X,Y> |
bimap(F<A,X> left,
F<B,Y> right)
Map the given functions across the appropriate side.
|
static <A,B,X> F<Either<A,B>,X> |
either_(F<A,X> left,
F<B,X> right)
First class catamorphism for either.
|
abstract <X> X |
either(F<A,X> left,
F<B,X> right)
The catamorphism for either.
|
boolean |
equals(java.lang.Object other) |
int |
hashCode() |
static <A,B> Either<A,B> |
iif(boolean c,
F0<B> right,
F0<A> left)
If the condition satisfies, return the given A in left, otherwise, return the given B in right.
|
abstract boolean |
isLeft()
Returns
true if this either is a left, false otherwise. |
abstract boolean |
isRight()
Returns
true if this either is a right, false otherwise. |
static <A,B> Either<A,B> |
joinLeft(Either<Either<A,B>,B> e)
Joins an either through left.
|
static <A,B> Either<A,B> |
joinRight(Either<A,Either<A,B>> e)
Joins an either through right.
|
static <A,B> F<A,Either<A,B>> |
left_()
A function that constructs a left value of either.
|
Either.LeftProjection<A,B> |
left()
Projects this either as a left.
|
static <A,B> Either<A,B> |
left(A a)
Construct a left value of either.
|
static <A,B,X> F<F<A,X>,F<Either<A,B>,Either<X,B>>> |
leftMap_() |
static <A,B> List<A> |
lefts(List<Either<A,B>> es)
Returns all the left values in the given list.
|
static <A> A |
reduce(Either<A,A> e)
Takes an
Either to its contained value within left or right. |
static <A,B> F<B,Either<A,B>> |
right_()
A function that constructs a right value of either.
|
Either.RightProjection<A,B> |
right()
Projects this either as a right.
|
static <A,B> Either<A,B> |
right(B b)
Construct a right value of either.
|
static <A,B,X> F<F<B,X>,F<Either<A,B>,Either<A,X>>> |
rightMap_() |
static <A,B> List<B> |
rights(List<Either<A,B>> es)
Returns all the right values in the given list.
|
static <A,X> Either<List<A>,X> |
sequenceLeft(List<Either<A,X>> a)
Sequences through the left side of the either monad with a list of values.
|
static <B,X> Either<X,List<B>> |
sequenceRight(List<Either<X,B>> a)
Sequences through the right side of the either monad with a list of values.
|
Either<B,A> |
swap()
If this is a left, then return the left value in right, or vice versa.
|
java.lang.String |
toString() |
<C> IO<Either<C,B>> |
traverseIOLeft(F<A,IO<C>> f)
Traversable instance of LeftProjection of Either for IO.
|
<C> IO<Either<A,C>> |
traverseIORight(F<B,IO<C>> f)
Traversable instance of RightProjection of Either for IO.
|
<C> List<Either<C,B>> |
traverseListLeft(F<A,List<C>> f)
Traversable instance of LeftProjection of Either for List.
|
<C> List<Either<A,C>> |
traverseListRight(F<B,List<C>> f)
Traversable instance of RightProjection of Either for List.
|
<C> Option<Either<C,B>> |
traverseOptionLeft(F<A,Option<C>> f)
Traversable instance of LeftProjection of Either for Option.
|
<C> Option<Either<A,C>> |
traverseOptionRight(F<B,Option<C>> f)
Traversable instance of RightProjection of Either for Option.
|
<C> Stream<Either<C,B>> |
traverseStreamLeft(F<A,Stream<C>> f)
Traversable instance of LeftProjection of Either for Stream.
|
<C> Stream<Either<A,C>> |
traverseStreamRight(F<B,Stream<C>> f)
Traversable instance of RightProjection of Either for Stream.
|
public final Either.LeftProjection<A,B> left()
public final Either.RightProjection<A,B> right()
public abstract boolean isLeft()
true if this either is a left, false otherwise.true if this either is a left, false otherwise.public abstract boolean isRight()
true if this either is a right, false otherwise.true if this either is a right, false otherwise.public abstract <X> X either(F<A,X> left, F<B,X> right)
left - The function to call if this is left.right - The function to call if this is right.public final <X,Y> Either<X,Y> bimap(F<A,X> left, F<B,Y> right)
left - The function to map if this is left.right - The function to map if this is right.public final boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic final int hashCode()
hashCode in class java.lang.Objectpublic final Either<B,A> swap()
public static <A,B> Either<A,B> left(A a)
a - The value underlying the either.public static <A,B> F<A,Either<A,B>> left_()
public static <A,B> F<B,Either<A,B>> right_()
public static <A,B> Either<A,B> right(B b)
b - The value underlying the either.public static <A,B,X> F<Either<A,B>,X> either_(F<A,X> left, F<B,X> right)
left - The function to call if this is left.right - The function to call if this is right.public static <A,B,X> F<F<A,X>,F<Either<A,B>,Either<X,B>>> leftMap_()
public static <A,B,X> F<F<B,X>,F<Either<A,B>,Either<A,X>>> rightMap_()
public static <A,B> Either<A,B> joinLeft(Either<Either<A,B>,B> e)
e - The either of either to join.public static <A,B> Either<A,B> joinRight(Either<A,Either<A,B>> e)
e - The either of either to join.public static <A,X> Either<List<A>,X> sequenceLeft(List<Either<A,X>> a)
a - The list of values to sequence with the either monad.public static <B,X> Either<X,List<B>> sequenceRight(List<Either<X,B>> a)
a - The list of values to sequence with the either monad.public final <C> List<Either<A,C>> traverseListRight(F<B,List<C>> f)
public final <C> List<Either<C,B>> traverseListLeft(F<A,List<C>> f)
public final <C> IO<Either<A,C>> traverseIORight(F<B,IO<C>> f)
public final <C> IO<Either<C,B>> traverseIOLeft(F<A,IO<C>> f)
public final <C> Option<Either<A,C>> traverseOptionRight(F<B,Option<C>> f)
public final <C> Option<Either<C,B>> traverseOptionLeft(F<A,Option<C>> f)
public final <C> Stream<Either<A,C>> traverseStreamRight(F<B,Stream<C>> f)
public final <C> Stream<Either<C,B>> traverseStreamLeft(F<A,Stream<C>> f)
public static <A> A reduce(Either<A,A> e)
Either to its contained value within left or right.e - The either to reduce.Either to its contained value within left or right.public static <A,B> Either<A,B> iif(boolean c, F0<B> right, F0<A> left)
c - The condition to test.right - The right value to use if the condition satisfies.left - The left value to use if the condition does not satisfy.public static <A,B> List<A> lefts(List<Either<A,B>> es)
es - The list of possible left values.public static <A,B> List<B> rights(List<Either<A,B>> es)
es - The list of possible right values.public final java.lang.String toString()
toString in class java.lang.Object