Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.

fj.data
Class Either.LeftProjection<A,B>

java.lang.Object
  extended by fj.data.Either.LeftProjection<A,B>
All Implemented Interfaces:
Iterable<A>
Enclosing class:
Either<A,B>

public final class Either.LeftProjection<A,B>
extends Object
implements Iterable<A>

A left projection of an either value.


Method Summary
<X> Either<X,B>
apply(Either<F<A,X>,B> e)
          Function application on this projection's value.
<X> Either<X,B>
bind(F<A,Either<X,B>> f)
          Binds the given function across this projection's value if it has one.
 Either<A,B> either()
          The either value underlying this projection.
 boolean exists(F<A,Boolean> f)
          Returns false if no value or returns the result of the application of the given function to the value.
<X> Option<Either<A,X>>
filter(F<A,Boolean> f)
          Returns None if this projection has no value or if the given predicate p does not hold for the value, otherwise, returns a right in Some.
 boolean forall(F<A,Boolean> f)
          Returns true if no value or returns the result of the application of the given function to the value.
 void foreach(Effect<A> f)
          Execute a side-effect on this projection's value if it has one.
 Unit foreach(F<A,Unit> f)
          Execute a side-effect on this projection's value if it has one.
 Iterator<A> iterator()
          Returns an iterator for this projection.
<X> Either<X,B>
map(F<A,X> f)
          Map the given function across this projection's value if it has one.
 A on(F<B,A> f)
          The value of this projection or the result of the given function on the opposing projection's value.
 A orValue(A a)
          The value of this projection or the given argument.
 A orValue(P1<A> a)
          The value of this projection or the given argument.
<X> Either<X,B>
sequence(Either<X,B> e)
          Anonymous bind through this projection.
 Array<A> toArray()
          Returns a single element array if this projection has a value, otherwise an empty array.
 Collection<A> toCollection()
          Projects an immutable collection of this projection.
 List<A> toList()
          Returns a single element list if this projection has a value, otherwise an empty list.
 Option<A> toOption()
          Returns this projection's value in Some if it exists, otherwise None.
 Stream<A> toStream()
          Returns a single element stream if this projection has a value, otherwise an empty stream.
 A value()
          The value of this projection or fails with a specialised error message.
 A valueE(P1<String> err)
          Returns the value of this projection or fails with the given error message.
 A valueE(String err)
          Returns the value of this projection or fails with the given error message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

iterator

public Iterator<A> iterator()
Returns an iterator for this projection. This method exists to permit the use in a for-each loop.

Specified by:
iterator in interface Iterable<A>
Returns:
A iterator for this projection.

either

public Either<A,B> either()
The either value underlying this projection.

Returns:
The either value underlying this projection.

valueE

public A valueE(P1<String> err)
Returns the value of this projection or fails with the given error message.

Parameters:
err - The error message to fail with.
Returns:
The value of this projection

valueE

public A valueE(String err)
Returns the value of this projection or fails with the given error message.

Parameters:
err - The error message to fail with.
Returns:
The value of this projection

value

public A value()
The value of this projection or fails with a specialised error message.

Returns:
The value of this projection.

orValue

public A orValue(P1<A> a)
The value of this projection or the given argument.

Parameters:
a - The value to return if this projection has no value.
Returns:
The value of this projection or the given argument.

orValue

public A orValue(A a)
The value of this projection or the given argument.

Parameters:
a - The value to return if this projection has no value.
Returns:
The value of this projection or the given argument.

on

public A on(F<B,A> f)
The value of this projection or the result of the given function on the opposing projection's value.

Parameters:
f - The function to execute if this projection has no value.
Returns:
The value of this projection or the result of the given function on the opposing projection's value.

foreach

public Unit foreach(F<A,Unit> f)
Execute a side-effect on this projection's value if it has one.

Parameters:
f - The side-effect to execute.
Returns:
The unit value.

foreach

public void foreach(Effect<A> f)
Execute a side-effect on this projection's value if it has one.

Parameters:
f - The side-effect to execute.

map

public <X> Either<X,B> map(F<A,X> f)
Map the given function across this projection's value if it has one.

Parameters:
f - The function to map across this projection.
Returns:
A new either value after mapping.

bind

public <X> Either<X,B> bind(F<A,Either<X,B>> f)
Binds the given function across this projection's value if it has one.

Parameters:
f - The function to bind across this projection.
Returns:
A new either value after binding.

sequence

public <X> Either<X,B> sequence(Either<X,B> e)
Anonymous bind through this projection.

Parameters:
e - The value to bind with.
Returns:
An either after binding through this projection.

filter

public <X> Option<Either<A,X>> filter(F<A,Boolean> f)
Returns None if this projection has no value or if the given predicate p does not hold for the value, otherwise, returns a right in Some.

Parameters:
f - The predicate function to test on this projection's value.
Returns:
None if this projection has no value or if the given predicate p does not hold for the value, otherwise, returns a right in Some.

apply

public <X> Either<X,B> apply(Either<F<A,X>,B> e)
Function application on this projection's value.

Parameters:
e - The either of the function to apply on this projection's value.
Returns:
The result of function application within either.

forall

public boolean forall(F<A,Boolean> f)
Returns true if no value or returns the result of the application of the given function to the value.

Parameters:
f - The predicate function to test on this projection's value.
Returns:
true if no value or returns the result of the application of the given function to the value.

exists

public boolean exists(F<A,Boolean> f)
Returns false if no value or returns the result of the application of the given function to the value.

Parameters:
f - The predicate function to test on this projection's value.
Returns:
false if no value or returns the result of the application of the given function to the value.

toList

public List<A> toList()
Returns a single element list if this projection has a value, otherwise an empty list.

Returns:
A single element list if this projection has a value, otherwise an empty list.

toOption

public Option<A> toOption()
Returns this projection's value in Some if it exists, otherwise None.

Returns:
This projection's value in Some if it exists, otherwise None.

toArray

public Array<A> toArray()
Returns a single element array if this projection has a value, otherwise an empty array.

Returns:
A single element array if this projection has a value, otherwise an empty array.

toStream

public Stream<A> toStream()
Returns a single element stream if this projection has a value, otherwise an empty stream.

Returns:
A single element stream if this projection has a value, otherwise an empty stream.

toCollection

public Collection<A> toCollection()
Projects an immutable collection of this projection.

Returns:
An immutable collection of this projection.

Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.