Package fj.data
Class Either.RightProjection<A,B>
- java.lang.Object
-
- fj.data.Either.RightProjection<A,B>
-
-
Constructor Summary
Constructors Modifier Constructor Description private
RightProjection(Either<A,B> e)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <X> Either<A,X>
apply(Either<A,F<B,X>> e)
Function application on this projection's value.<X> Either<A,X>
bind(F<B,Either<A,X>> 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<B,java.lang.Boolean> f)
Returnsfalse
if no value or returns the result of the application of the given function to the value.<X> Option<Either<X,B>>
filter(F<B,java.lang.Boolean> f)
ReturnsNone
if this projection has no value or if the given predicatep
does not hold for the value, otherwise, returns a left inSome
.boolean
forall(F<B,java.lang.Boolean> f)
Returnstrue
if no value or returns the result of the application of the given function to the value.Unit
foreach(F<B,Unit> f)
Execute a side-effect on this projection's value if it has one.void
foreachDoEffect(Effect1<B> f)
Execute a side-effect on this projection's value if it has one.java.util.Iterator<B>
iterator()
Returns an iterator for this projection.<X> Either<A,X>
map(F<B,X> f)
Map the given function across this projection's value if it has one.B
on(F<A,B> f)
The value of this projection or the result of the given function on the opposing projection's value.B
orValue(B a)
The value of this projection or the given argument.B
orValue(F0<B> b)
The value of this projection or the given argument.<X> Either<A,X>
sequence(Either<A,X> e)
Anonymous bind through this projection.Array<B>
toArray()
Returns a single element array if this projection has a value, otherwise an empty array.java.util.Collection<B>
toCollection()
Projects an immutable collection of this projection.List<B>
toList()
Returns a single element list if this projection has a value, otherwise an empty list.Option<B>
toOption()
Returns this projection's value inSome
if it exists, otherwiseNone
.Stream<B>
toStream()
Returns a single element stream if this projection has a value, otherwise an empty stream.<C> IO<Either<A,C>>
traverseIO(F<B,IO<C>> f)
Traverse with a function that has IO effect<C> List<Either<A,C>>
traverseList(F<B,List<C>> f)
Traverse with function that produces List (non-determinism).<C> Option<Either<A,C>>
traverseOption(F<B,Option<C>> f)
Traverse this right with the given function and collect the output as an option.<C> P1<Either<A,C>>
traverseP1(F<B,P1<C>> f)
Traverse this right with the given function and collect the output as a p1.<C> Stream<Either<A,C>>
traverseStream(F<B,Stream<C>> f)
B
value()
The value of this projection or fails with a specialised error message.B
valueE(F0<java.lang.String> err)
Returns the value of this projection or fails with the given error message.B
valueE(java.lang.String err)
Returns the value of this projection or fails with the given error message.
-
-
-
Method Detail
-
iterator
public java.util.Iterator<B> iterator()
Returns an iterator for this projection. This method exists to permit the use in afor
-each loop.- Specified by:
iterator
in interfacejava.lang.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 B valueE(java.lang.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 B valueE(F0<java.lang.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 B value()
The value of this projection or fails with a specialised error message.- Returns:
- The value of this projection.
-
orValue
public B orValue(B 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 B orValue(F0<B> b)
The value of this projection or the given argument.- Parameters:
b
- The value to return if this projection has no value.- Returns:
- The value of this projection or the given argument.
-
on
public B on(F<A,B> 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<B,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.
-
foreachDoEffect
public void foreachDoEffect(Effect1<B> 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<A,X> map(F<B,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<A,X> bind(F<B,Either<A,X>> 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<A,X> sequence(Either<A,X> e)
Anonymous bind through this projection.- Parameters:
e
- The value to bind with.- Returns:
- An either after binding through this projection.
-
traverseList
public <C> List<Either<A,C>> traverseList(F<B,List<C>> f)
Traverse with function that produces List (non-determinism).- Parameters:
f
- the function to traverse with- Returns:
- An either after traversing through this projection.
-
traverseIO
public <C> IO<Either<A,C>> traverseIO(F<B,IO<C>> f)
Traverse with a function that has IO effect- Parameters:
f
- the function to traverse with- Returns:
- An either after traversing through this projection.
-
traverseP1
public <C> P1<Either<A,C>> traverseP1(F<B,P1<C>> f)
Traverse this right with the given function and collect the output as a p1.- Type Parameters:
C
- the type of the p1 value- Parameters:
f
- the given function- Returns:
- the p1
-
traverseOption
public <C> Option<Either<A,C>> traverseOption(F<B,Option<C>> f)
Traverse this right with the given function and collect the output as an option.- Type Parameters:
C
- the type of the option value- Parameters:
f
- the given function- Returns:
- the option
-
filter
public <X> Option<Either<X,B>> filter(F<B,java.lang.Boolean> f)
ReturnsNone
if this projection has no value or if the given predicatep
does not hold for the value, otherwise, returns a left inSome
.- Parameters:
f
- The predicate function to test on this projection's value.- Returns:
None
if this projection has no value or if the given predicatep
does not hold for the value, otherwise, returns a left inSome
.
-
apply
public <X> Either<A,X> apply(Either<A,F<B,X>> 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<B,java.lang.Boolean> f)
Returnstrue
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<B,java.lang.Boolean> f)
Returnsfalse
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<B> 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<B> toOption()
Returns this projection's value inSome
if it exists, otherwiseNone
.- Returns:
- This projection's value in
Some
if it exists, otherwiseNone
.
-
toArray
public Array<B> 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<B> 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 java.util.Collection<B> toCollection()
Projects an immutable collection of this projection.- Returns:
- An immutable collection of this projection.
-
-