jedi.either
Class Either<A,B>

java.lang.Object
  extended by jedi.either.Either<A,B>
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Left, Right

public abstract class Either<A,B>
extends Object
implements Serializable

The Either type represents a value of one of two possible types (a disjoint union) and was Inspired by Scala's Either.

See Also:
Serialized Form

Constructor Summary
Either()
           
 
Method Summary
abstract  List<A> asList()
           
static
<A,B> Either<A,B>
cond(boolean cond, A a, B b)
          If the condition satisfies, return the given A in Left, otherwise, return the given B in Right.
static
<A,B> Either<A,B>
cond(boolean cond, Functor0<A> a, Functor0<B> b)
          If the condition satisfies, return the result of executing a in Left, otherwise, return the result of executing b in Right.
abstract  void execute(Command<A> ca, Command<B> cb)
           
abstract
<X> Either<X,B>
flatMap(Functor<? super A,Either<X,B>> f)
           
abstract
<X> X
fold(Functor<? super A,X> fa, Functor<? super B,X> fb)
          Deconstruction of the type.
 boolean isLeft()
           
 boolean isRight()
           
 LeftProjection<A,B> left()
           
abstract
<X> Either<X,B>
map(Functor<? super A,X> f)
          Maps the function argument through Left.
 RightProjection<A,B> right()
           
abstract  Either<B,A> swap()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Either

public Either()
Method Detail

cond

public static <A,B> Either<A,B> cond(boolean cond,
                                     A a,
                                     B b)
If the condition satisfies, return the given A in Left, otherwise, return the given B in Right.


cond

public static <A,B> Either<A,B> cond(boolean cond,
                                     Functor0<A> a,
                                     Functor0<B> b)
If the condition satisfies, return the result of executing a in Left, otherwise, return the result of executing b in Right.


isLeft

public boolean isLeft()

isRight

public boolean isRight()

left

public LeftProjection<A,B> left()

right

public RightProjection<A,B> right()

fold

public abstract <X> X fold(Functor<? super A,X> fa,
                           Functor<? super B,X> fb)
Deconstruction of the type.

Parameters:
fa - the functor to apply if this is a Left
fb - the functor to apply if this is a Left
Returns:
the result of applying the appropriate functor.

execute

public abstract void execute(Command<A> ca,
                             Command<B> cb)

swap

public abstract Either<B,A> swap()

asList

public abstract List<A> asList()
Returns:
Singleton list if Lift or empty list if Right.

map

public abstract <X> Either<X,B> map(Functor<? super A,X> f)
Maps the function argument through Left.


flatMap

public abstract <X> Either<X,B> flatMap(Functor<? super A,Either<X,B>> f)


Copyright © 2011. All Rights Reserved.