com.evolvedbinary.functional
Class Either<L,R>

java.lang.Object
  extended by com.evolvedbinary.functional.Either<L,R>
Type Parameters:
L - Type of left-hand-side parameter
R - Type of right-hand-side parameter
Direct Known Subclasses:
Either.Left, Either.Right

public abstract class Either<L,R>
extends Object

A disjunction, more basic than but similar to scala.util.Either in addition it is also right-biased in a similar way to scalaz.\/

Author:
Adam Retter

Nested Class Summary
static class Either.Left<L,R>
           
 class Either.LeftProjection<L,R>
           
static class Either.Right<L,R>
           
 class Either.RightProjection<L,R>
           
 
Method Summary
 boolean equals(Object obj)
           
<LL extends L,T>
Either<LL,T>
flatMap(Function<R,Either<LL,T>> f)
          Bind through on the right-hand-side of this disjunction
<T> T
fold(Function<L,T> lf, Function<R,T> rf)
          Catamorphism.
 boolean isLeft()
           
 boolean isRight()
           
 Either.LeftProjection<L,R> left()
           
static
<L,R> Either<L,R>
Left(L value)
           
<T> Either<T,R>
leftMap(Function<L,T> f)
          Map on the left-hand-side of the disjunction
<T> Either<L,T>
map(Function<R,T> f)
          Map on the right-hand-side of the disjunction
 Either.RightProjection<L,R> right()
           
static
<L,R> Either<L,R>
Right(R value)
           
<RR extends R>
RR
valueOr(Function<L,RR> lf)
          Return the value from the right-hand-side of this disjunction or run the function on the left-hand-side
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isLeft

public final boolean isLeft()

isRight

public final boolean isRight()

left

public final Either.LeftProjection<L,R> left()

right

public final Either.RightProjection<L,R> right()

map

public final <T> Either<L,T> map(Function<R,T> f)
Map on the right-hand-side of the disjunction

Parameters:
f - The function to map with

flatMap

public final <LL extends L,T> Either<LL,T> flatMap(Function<R,Either<LL,T>> f)
Bind through on the right-hand-side of this disjunction

Parameters:
f - the function to bind through

leftMap

public final <T> Either<T,R> leftMap(Function<L,T> f)
Map on the left-hand-side of the disjunction

Parameters:
f - The function to map with

fold

public final <T> T fold(Function<L,T> lf,
                        Function<R,T> rf)
Catamorphism. Run the first given function if left, otherwise the second given function

Type Parameters:
T - The result type from performing the fold
Parameters:
lf - A function that may be applied to the left-hand-side
rf - A function that may be applied to the right-hand-side

valueOr

public final <RR extends R> RR valueOr(Function<L,RR> lf)
Return the value from the right-hand-side of this disjunction or run the function on the left-hand-side

Type Parameters:
RR - The result type
Parameters:
lf - A function that may be applied to the left-hand-side

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

Left

public static final <L,R> Either<L,R> Left(L value)

Right

public static final <L,R> Either<L,R> Right(R value)


Copyright © 2016 Evolved Binary Ltd.. All Rights Reserved.