public class Eithers extends Object
| Modifier and Type | Method and Description |
|---|---|
static <L,R> Either<L,R> |
cond(boolean predicate,
L left,
R right)
Creates an Either based on a boolean expression.
|
static <L,R> Iterable<L> |
filterLeft(Iterable<Either<L,R>> it)
|
static <L,R> Iterable<R> |
filterRight(Iterable<Either<L,R>> it)
|
static <X extends Exception,A> |
getOrThrow(Either<X,A> either)
Simplifies extracting a value or throwing a checked exception from an
Either.
|
static <L,R> Predicate<Either<L,R>> |
isLeft()
A predicate that tests if the supplied either is a left.
|
static <L,R> Predicate<Either<L,R>> |
isRight()
A predicate that tests if the supplied either is a right.
|
static <L,R> Function<Either<L,R>,Option<L>> |
leftMapper()
A function that maps an either to an option of its left type.
|
static <T> T |
merge(Either<T,T> either)
Extracts an object from an Either, regardless of the side in which it is
stored, provided both sides contain the same type.
|
static <L,R> Function<Either<L,R>,Option<R>> |
rightMapper()
A function that maps an either to an option of its right type.
|
static <L,R> Either<Iterable<L>,R> |
sequenceLeft(Iterable<Either<L,R>> eithers)
Collect the left values if there are only lefts, otherwise return the first
right encountered.
|
static <L,R> Either<L,Iterable<R>> |
sequenceRight(Iterable<Either<L,R>> eithers)
Collect the right values if there are only rights, otherwise return the
first left encountered.
|
static <L,R> Function<L,Either<L,R>> |
toLeft()
Function to convert from an value to a
Either.Left containing that value. |
static <L,R> Function<L,Either<L,R>> |
toLeft(Class<L> leftType,
Class<R> rightType)
Function to convert from a value to a
Either.Left containing that value. |
static <L,R> Supplier<Either<L,R>> |
toLeft(L l)
Supplier returning a
Either.Left. |
static <L,R> Supplier<Either<L,R>> |
toLeft(L l,
Class<R> rightType)
Supplier returning a
Either.Left. |
static <L,R> Function<R,Either<L,R>> |
toRight()
Function to convert from an value to a
Either.Right. |
static <L,R> Function<R,Either<L,R>> |
toRight(Class<L> leftType,
Class<R> rightType)
Function to convert from a value to a
Either.Right containing that value. |
static <L,R> Supplier<Either<L,R>> |
toRight(Class<L> leftType,
R r)
Supplier returning a
Either.Right. |
static <L,R> Supplier<Either<L,R>> |
toRight(R r)
Supplier returning a
Either.Right. |
static <LL,L extends LL,R> |
upcastLeft(Either<L,R> e)
Upcasts an
either of left type L to an either of left type
LL, which is a super type of L, keeping the right type unchanged. |
static <L,RR,R extends RR> |
upcastRight(Either<L,R> e)
Upcasts an
either of right type R to an either of right type
RR, which is a super type of R, keeping the left type unchanged. |
public static <T> T merge(Either<T,T> either)
T - the type for both the LHS and the RHSeither - use whichever side holds the value to returnpublic static <L,R> Either<L,R> cond(boolean predicate, L left, R right)
L - the LHS typeR - the RHS typepredicate - if predicate is true, a Right will be returned if it is
false, a Left will be returned containing the supplied left value.left - the LHS valueright - the RHS valuepublic static <X extends Exception,A> A getOrThrow(Either<X,A> either) throws X extends Exception
A - the value typeX - the exception typeeither - to extract fromX - the exception on the LHSX extends Exceptionpublic static <L,R> Predicate<Either<L,R>> isLeft()
L - the LHS typeR - the RHS typepublic static <L,R> Predicate<Either<L,R>> isRight()
L - the LHS typeR - the RHS typepublic static <L,R> Function<Either<L,R>,Option<L>> leftMapper()
Option containing the
either's left value if {Either#isLeft()} is true, an undefined
Option otherwise.L - the LHS typeR - the RHS typepublic static <L,R> Function<Either<L,R>,Option<R>> rightMapper()
Option containing the
either's right value if {Either#isRight()} is true, an undefined
Option otherwise.L - the LHS typeR - the RHS typepublic static <L,R> Function<L,Either<L,R>> toLeft()
Either.Left containing that value.L - left type.R - right type.Function returning a
Either.Left.public static <L,R> Function<L,Either<L,R>> toLeft(Class<L> leftType, Class<R> rightType)
Either.Left containing that value. Allows
hinting the correct types.L - left type.R - right type.leftType - expected left type.rightType - expected right type.Function returning a
Either.Left.public static <L,R> Supplier<Either<L,R>> toLeft(L l)
Either.Left.L - left type.R - right type.l - value to return inside the left.Supplier returning a
Either.Left..public static <L,R> Supplier<Either<L,R>> toLeft(L l, Class<R> rightType)
Either.Left. Allows hinting
the correct right type.L - left type.R - right type.l - value to return inside the left.rightType - type hint for the right type of the either.Supplier returning a
Either.Left.public static <L,R> Function<R,Either<L,R>> toRight()
Either.Right. Allows hinting the correct types.L - left type.R - right type.Function returning a
Either.Right.public static <L,R> Function<R,Either<L,R>> toRight(Class<L> leftType, Class<R> rightType)
Either.Right containing that value. Allows
hinting the correct types.L - left type.R - right type.leftType - expected left type.rightType - expected right type.Function returning a
Either.Right.public static <L,R> Supplier<Either<L,R>> toRight(R r)
Either.Right.L - left type.R - right type.r - value to return inside the right.Supplier returning a
Either.Right..public static <L,R> Supplier<Either<L,R>> toRight(Class<L> leftType, R r)
Either.Right. Allows
hinting the correct right type.L - left type.R - right type.r - value to return inside the right.leftType - type hint for the left type of the either.Supplier returning a
Either.Right.public static <LL,L extends LL,R> Either<LL,R> upcastLeft(Either<L,R> e)
either of left type L to an either of left type
LL, which is a super type of L, keeping the right type unchanged.L - the base type to upcastLL - the super type of the contained left typeR - the contained right typee - the source eitherpublic static <L,RR,R extends RR> Either<L,RR> upcastRight(Either<L,R> e)
either of right type R to an either of right type
RR, which is a super type of R, keeping the left type unchanged.L - the contained left typeR - the base type to upcastRR - the super type of the contained right typee - the source eitherpublic static <L,R> Iterable<L> filterLeft(Iterable<Either<L,R>> it)
L - the LHS typeR - the RHS typeit - iterable of eithers to filter and transform frompublic static <L,R> Iterable<R> filterRight(Iterable<Either<L,R>> it)
L - the LHS typeR - the RHS typeit - iterable of eithers to filter and transform frompublic static <L,R> Either<L,Iterable<R>> sequenceRight(Iterable<Either<L,R>> eithers)
L - the LHS typeR - the RHS typeeithers - an Iterable of either valuespublic static <L,R> Either<Iterable<L>,R> sequenceLeft(Iterable<Either<L,R>> eithers)
L - the LHS typeR - the RHS typeeithers - an Iterable of either valuesCopyright © 2017 Atlassian. All rights reserved.