public class Eithers extends Object
Constructor and Description |
---|
Eithers() |
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 right values if there are only rights, otherwise return the
first left 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.
|
public static <T> T merge(Either<T,T> either)
public static <L,R> Either<L,R> cond(boolean predicate, L left, R right)
public static <X extends Exception,A> A getOrThrow(Either<X,A> either) throws X extends Exception
X
- the exception typeA
- the value typeeither
- to extract fromX
- the exception on the LHSX extends Exception
public static <L,R> Either<L,Iterable<R>> sequenceRight(Iterable<Either<L,R>> eithers)
L
- the left typeR
- eithers
- an Iterable of Eitherpublic static <L,R> Either<Iterable<L>,R> sequenceLeft(Iterable<Either<L,R>> eithers)
L
- the left typeR
- eithers
- an Iterable of Eitherpublic static <L,R> Predicate<Either<L,R>> isLeft()
public static <L,R> Predicate<Either<L,R>> isRight()
public static <L,R> Function<Either<L,R>,Option<L>> leftMapper()
public static <L,R> Function<Either<L,R>,Option<R>> rightMapper()
public static <L,R> Iterable<L> filterLeft(Iterable<Either<L,R>> it)
it
- iterable of eithers to filter and transform fromCopyright © 2013 Atlassian. All rights reserved.