Package fj.data
Class Either<A,B>
java.lang.Object
fj.data.Either<A,B>
- Direct Known Subclasses:
Either.Left,Either.Right
The
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.- Version:
- %build.number%
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classstatic final classA left projection of an either value.private static final classstatic final classA right projection of an either value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <X,Y> Either <X, Y> Map the given functions across the appropriate side.abstract <X> XThe catamorphism for either.First class catamorphism for either.final booleanfinal inthashCode()static <A,B> Either <A, B> If the condition satisfies, return the given B in right, otherwise, return the given A in left.abstract booleanisLeft()Returnstrueif this either is a left,falseotherwise.abstract booleanisRight()Returnstrueif this either is a right,falseotherwise.static <A,B> Either <A, B> Joins an either through left.static <A,B> Either <A, B> Joins an either through right.final 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.left_()A function that constructs a left value of either.Map the given function across this either's left projection.leftMap_()Return a function that maps a given function across this either's left projection.static <A,B> List <A> Returns all the left values in the given list.static <A> ATakes anEitherto its contained value within left or right.final 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.right_()A function that constructs a right value of either.Map the given function across this either's right.Return a function that maps a given function across this either's right projection.static <A,B> List <B> Returns all the right values in the given list.sequenceLeft(List<Either<A, X>> a) Sequences through the left side of the either monad with a list of values.sequenceRight(List<Either<X, B>> a) Sequences through the right side of the either monad with a list of values.swap()If this is a left, then return the left value in right, or vice versa.final StringtoString()traverseIOLeft(F<A, IO<C>> f) Traversable instance of LeftProjection of Either for IO.traverseIORight(F<B, IO<C>> f) Traversable instance of RightProjection of Either for IO.traverseListLeft(F<A, List<C>> f) Traversable instance of LeftProjection of Either for List.traverseListRight(F<B, List<C>> f) Traversable instance of RightProjection of Either for List.traverseOptionLeft(F<A, Option<C>> f) Traversable instance of LeftProjection of Either for Option.traverseOptionRight(F<B, Option<C>> f) Traversable instance of RightProjection of Either for Option.traverseStreamLeft(F<A, Stream<C>> f) Traversable instance of LeftProjection of Either for Stream.traverseStreamRight(F<B, Stream<C>> f) Traversable instance of RightProjection of Either for Stream.
-
Constructor Details
-
Either
private Either()
-
-
Method Details
-
left
Projects this either as a left.- Returns:
- A left projection of this either.
-
right
Projects this either as a right.- Returns:
- A right projection of this either.
-
isLeft
public abstract boolean isLeft()Returnstrueif this either is a left,falseotherwise.- Returns:
trueif this either is a left,falseotherwise.
-
isRight
public abstract boolean isRight()Returnstrueif this either is a right,falseotherwise.- Returns:
trueif this either is a right,falseotherwise.
-
either
The catamorphism for either. Folds over this either breaking into left or right.- Parameters:
left- The function to call if this is left.right- The function to call if this is right.- Returns:
- The reduced value.
-
bimap
Map the given functions across the appropriate side.- Parameters:
left- The function to map if this is left.right- The function to map if this is right.- Returns:
- A new either value after mapping with the appropriate function applied.
-
equals
-
hashCode
public final int hashCode() -
swap
If this is a left, then return the left value in right, or vice versa.- Returns:
- The value of this either swapped to the opposing side.
-
left
Construct a left value of either.- Parameters:
a- The value underlying the either.- Returns:
- A left value of either.
-
left_
A function that constructs a left value of either.- Returns:
- A function that constructs a left value of either.
-
right_
A function that constructs a right value of either.- Returns:
- A function that constructs a right value of either.
-
right
Construct a right value of either.- Parameters:
b- The value underlying the either.- Returns:
- A right value of either.
-
either_
First class catamorphism for either. Folds over this either breaking into left or right.- Parameters:
left- The function to call if this is left.right- The function to call if this is right.- Returns:
- The reducing function.
-
leftMap
Map the given function across this either's left projection.- Type Parameters:
X- the type of the function output- Parameters:
f- the given function- Returns:
- the either
-
leftMap_
Return a function that maps a given function across this either's left projection.- Type Parameters:
A- the type of the right valueB- the type of the left valueX- the type of the function output- Returns:
- A function that maps another function across an either's left projection.
-
rightMap
Map the given function across this either's right.- Type Parameters:
X- the type of the function output- Parameters:
f- the given function- Returns:
- the either
-
rightMap_
Return a function that maps a given function across this either's right projection.- Type Parameters:
A- the type of the right valueB- the type of the left valueX- the type of the function output- Returns:
- A function that maps another function across an either's right projection.
-
joinLeft
Joins an either through left.- Parameters:
e- The either of either to join.- Returns:
- An either after joining.
-
joinRight
Joins an either through right.- Parameters:
e- The either of either to join.- Returns:
- An either after joining.
-
sequenceLeft
Sequences through the left side of the either monad with a list of values.- Parameters:
a- The list of values to sequence with the either monad.- Returns:
- A sequenced value.
- See Also:
-
sequenceRight
Sequences through the right side of the either monad with a list of values.- Parameters:
a- The list of values to sequence with the either monad.- Returns:
- A sequenced value.
- See Also:
-
traverseListRight
Traversable instance of RightProjection of Either for List.- Returns:
- traversed value
-
traverseListLeft
Traversable instance of LeftProjection of Either for List.- Returns:
- traversed value
-
traverseIORight
Traversable instance of RightProjection of Either for IO.- Returns:
- traversed value
-
traverseIOLeft
Traversable instance of LeftProjection of Either for IO.- Returns:
- traversed value
-
traverseOptionRight
Traversable instance of RightProjection of Either for Option.- Returns:
- traversed value
-
traverseOptionLeft
Traversable instance of LeftProjection of Either for Option.- Returns:
- traversed value
-
traverseStreamRight
Traversable instance of RightProjection of Either for Stream.- Returns:
- traversed value
-
traverseStreamLeft
Traversable instance of LeftProjection of Either for Stream.- Returns:
- traversed value
-
reduce
Takes anEitherto its contained value within left or right.- Parameters:
e- The either to reduce.- Returns:
- An
Eitherto its contained value within left or right.
-
iif
If the condition satisfies, return the given B in right, otherwise, return the given A in left.- Parameters:
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.- Returns:
- A constructed either based on the given condition.
-
lefts
Returns all the left values in the given list.- Parameters:
es- The list of possible left values.- Returns:
- All the left values in the given list.
-
rights
Returns all the right values in the given list.- Parameters:
es- The list of possible right values.- Returns:
- All the right values in the given list.
-
toString
-