|
Copyright Tony Morris 2008 This software is released under an open source BSD licence. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectfj.data.Option<A>
public abstract class Option<A>
An optional value that may be none (no value) or some (a value). This type is a replacement for
the use of null with better type checks.
| Method Summary | ||
|---|---|---|
|
apply(Option<F<A,B>> of)
Performs function application within an optional value (applicative functor pattern). |
|
|
bind(F<A,Option<B>> f)
Binds the given function across the element of this optional value with a final join. |
|
|
bind(Option<B> ob,
F<A,F<B,C>> f)
Binds the given function across the element of this optional value and the given optional value with a final join. |
|
|
bind(Option<B> ob,
Option<C> oc,
F<A,F<B,F<C,D>>> f)
Binds the given function across the element of this optional value and the given optional value with a final join. |
|
|
bind(Option<B> ob,
Option<C> oc,
Option<D> od,
F<A,F<B,F<C,F<D,E>>>> f)
Binds the given function across the element of this optional value and the given optional value with a final join. |
|
|
bind(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
F<A,F<B,F<C,F<D,F<E,F$>>>>> f)
Binds the given function across the element of this optional value and the given optional value with a final join. |
|
|
bind(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
Option<F$> of,
F<A,F<B,F<C,F<D,F<E,F<F$,G>>>>>> f)
Binds the given function across the element of this optional value and the given optional value with a final join. |
|
|
bind(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
Option<F$> of,
Option<G> og,
F<A,F<B,F<C,F<D,F<E,F<F$,F<G,H>>>>>>> f)
Binds the given function across the element of this optional value and the given optional value with a final join. |
|
|
bind(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
Option<F$> of,
Option<G> og,
Option<H> oh,
F<A,F<B,F<C,F<D,F<E,F<F$,F<G,F<H,I>>>>>>>> f)
Binds the given function across the element of this optional value and the given optional value with a final join. |
|
boolean |
exists(F<A,Boolean> f)
Returns true is this optional value has a value and the given predicate function
holds on that value, false otherwise. |
|
Option<A> |
filter(F<A,Boolean> f)
Filters elements from this optional value by returning only elements which produce true when the given function is applied to them. |
|
boolean |
forall(F<A,Boolean> f)
Returns true if this optional value has no value, or the predicate holds for the
given predicate function, false otherwise. |
|
void |
foreach(Effect<A> f)
Performs a side-effect for the value of this optional value. |
|
Unit |
foreach(F<A,Unit> f)
Performs a side-effect for the value of this optional value. |
|
static
|
fromNull(T t)
Turns an unsafe nullable value into a safe optional value. |
|
static F<String,Option<String>> |
fromString()
Returns a function that transforms a string to an optional non-empty string, or no value if the string is empty. |
|
static Option<String> |
fromString(String s)
Returns an optional non-empty string, or no value if the given string is empty. |
|
static
|
iif()
First-class version of the iif function. |
|
static
|
iif(F<A,Boolean> f,
A a)
Returns an optional value that has a value of the given argument, if the given predicate holds on that argument, otherwise, returns no value. |
|
boolean |
isNone()
Returns false if this optional value has a value, true otherwise. |
|
boolean |
isSome()
Returns true if this optional value has a value, false otherwise. |
|
Iterator<A> |
iterator()
Returns an iterator for this optional value. |
|
static
|
join(Option<Option<A>> o)
Joins the given optional value of optional value using a bind operation. |
|
int |
length()
Returns the length of this optional value; 1 is there is a value, 0 otherwise. |
|
|
map(F<A,B> f)
Maps the given function across this optional value. |
|
static
|
none()
Constructs an optional value that has no value. |
|
|
option(B b,
F<A,B> f)
Performs a reduction on this optional value using the given arguments. |
|
Option<A> |
orElse(Option<A> o)
Returns this optional value if there is one, otherwise, returns the argument optional value. |
|
Option<A> |
orElse(P1<Option<A>> o)
Returns this optional value if there is one, otherwise, returns the argument optional value. |
|
A |
orSome(A a)
Returns the value of this optional value or the given argument. |
|
A |
orSome(P1<A> a)
Returns the value of this optional value or the given argument. |
|
static
|
sequence(List<Option<A>> a)
Sequence through the option monad. |
|
|
sequence(Option<B> o)
Performs a bind across the optional value, but ignores the element value in the function. |
|
static
|
some_()
|
|
abstract A |
some()
Returns the value from this optional value, or fails if there is no value. |
|
static
|
some(T t)
Constructs an optional value that has a value of the given argument. |
|
static
|
somes(List<Option<A>> as)
Returns all the values in the given list. |
|
Array<A> |
toArray()
Returns an array projection of this optional value. |
|
Array<A> |
toArray(Class<A[]> c)
Returns an array projection of this optional value. |
|
Collection<A> |
toCollection()
Projects an immutable collection of this optional value. |
|
|
toEither(P1<X> x)
Returns an either projection of this optional value; the given argument in Left if
no value, or the value in Right. |
|
|
toEither(X x)
Returns an either projection of this optional value; the given argument in Left if
no value, or the value in Right. |
|
List<A> |
toList()
Returns a list projection of this optional value. |
|
Stream<A> |
toStream()
Returns a stream projection of this optional value. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public Iterator<A> iterator()
for-each loop.
iterator in interface Iterable<A>public abstract A some()
public boolean isSome()
true if this optional value has a value, false otherwise.
true if this optional value has a value, false otherwise.public boolean isNone()
false if this optional value has a value, true otherwise.
false if this optional value has a value, true otherwise.
public <B> B option(B b,
F<A,B> f)
b - The value to return if this optional value has no value.f - The function to apply to the value of this optional value.
public int length()
public A orSome(P1<A> a)
a - The argument to return if this optiona value has no value.
public A orSome(A a)
a - The argument to return if this optiona value has no value.
public <B> Option<B> map(F<A,B> f)
f - The function to map across this optional value.
public Unit foreach(F<A,Unit> f)
f - The side-effect to perform for the given element.
public void foreach(Effect<A> f)
f - The side-effect to perform for the given element.public Option<A> filter(F<A,Boolean> f)
true when the given function is applied to them.
f - The predicate function to filter on.
public <B> Option<B> bind(F<A,Option<B>> f)
f - The function to apply to the element of this optional value.
public <B,C> Option<C> bind(Option<B> ob,
F<A,F<B,C>> f)
ob - A given optional value to bind the given function with.f - The function to apply to the element of this optional value and the given optional
value.
public <B,C,D> Option<D> bind(Option<B> ob,
Option<C> oc,
F<A,F<B,F<C,D>>> f)
ob - A given optional value to bind the given function with.oc - A given optional value to bind the given function with.f - The function to apply to the element of this optional value and the given optional
value.
public <B,C,D,E> Option<E> bind(Option<B> ob,
Option<C> oc,
Option<D> od,
F<A,F<B,F<C,F<D,E>>>> f)
ob - A given optional value to bind the given function with.oc - A given optional value to bind the given function with.od - A given optional value to bind the given function with.f - The function to apply to the element of this optional value and the given optional
value.
public <B,C,D,E,F$> Option<F$> bind(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
F<A,F<B,F<C,F<D,F<E,F$>>>>> f)
ob - A given optional value to bind the given function with.oc - A given optional value to bind the given function with.od - A given optional value to bind the given function with.oe - A given optional value to bind the given function with.f - The function to apply to the element of this optional value and the given optional
value.
public <B,C,D,E,F$,G> Option<G> bind(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
Option<F$> of,
F<A,F<B,F<C,F<D,F<E,F<F$,G>>>>>> f)
ob - A given optional value to bind the given function with.oc - A given optional value to bind the given function with.od - A given optional value to bind the given function with.oe - A given optional value to bind the given function with.of - A given optional value to bind the given function with.f - The function to apply to the element of this optional value and the given optional
value.
public <B,C,D,E,F$,G,H> Option<H> bind(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
Option<F$> of,
Option<G> og,
F<A,F<B,F<C,F<D,F<E,F<F$,F<G,H>>>>>>> f)
ob - A given optional value to bind the given function with.oc - A given optional value to bind the given function with.od - A given optional value to bind the given function with.oe - A given optional value to bind the given function with.of - A given optional value to bind the given function with.og - A given optional value to bind the given function with.f - The function to apply to the element of this optional value and the given optional
value.
public <B,C,D,E,F$,G,H,I> Option<I> bind(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
Option<F$> of,
Option<G> og,
Option<H> oh,
F<A,F<B,F<C,F<D,F<E,F<F$,F<G,F<H,I>>>>>>>> f)
ob - A given optional value to bind the given function with.oc - A given optional value to bind the given function with.od - A given optional value to bind the given function with.oe - A given optional value to bind the given function with.of - A given optional value to bind the given function with.og - A given optional value to bind the given function with.oh - A given optional value to bind the given function with.f - The function to apply to the element of this optional value and the given optional
value.
public <B> Option<B> sequence(Option<B> o)
o - The optional value to apply in the final join.
public <B> Option<B> apply(Option<F<A,B>> of)
of - The optional value of functions to apply.
public Option<A> orElse(P1<Option<A>> o)
o - The optional value to return if this optional value has no value.
public Option<A> orElse(Option<A> o)
o - The optional value to return if this optional value has no value.
public <X> Either<X,A> toEither(P1<X> x)
Left if
no value, or the value in Right.
x - The value to return in left if this optional value has no value.
public <X> Either<X,A> toEither(X x)
Left if
no value, or the value in Right.
x - The value to return in left if this optional value has no value.
public List<A> toList()
public Stream<A> toStream()
public Array<A> toArray()
public Array<A> toArray(Class<A[]> c)
c - The class type of the array to return.
public boolean forall(F<A,Boolean> f)
true if this optional value has no value, or the predicate holds for the
given predicate function, false otherwise.
f - the predicate function to test on the value of this optional value.
true if this optional value has no value, or the predicate holds for the
given predicate function, false otherwise.public boolean exists(F<A,Boolean> f)
true is this optional value has a value and the given predicate function
holds on that value, false otherwise.
f - the predicate function to test on the value of this optional value.
true is this optional value has a value and the given predicate function
holds on that value, false otherwise.public Collection<A> toCollection()
public static <T> F<T,Option<T>> some_()
public static <T> Option<T> some(T t)
t - The value for the returned optional value.
public static <T> Option<T> none()
public static <T> Option<T> fromNull(T t)
t == null then
return none, otherwise, return the given value in some.
t - The unsafe nullable value.
t == null then return it in some, otherwise, return none.public static <A> Option<A> join(Option<Option<A>> o)
o - The optional value of optional value to join.
public static <A> Option<List<A>> sequence(List<Option<A>> a)
a - The list of option to sequence.
public static <A> Option<A> iif(F<A,Boolean> f,
A a)
f - The predicate to test on the given argument.a - The argument to test the predicate on and potentially use as the value of the returned
optional value.
public static <A> F2<F<A,Boolean>,A,Option<A>> iif()
public static <A> List<A> somes(List<Option<A>> as)
as - The list of potential values to get actual values from.
public static Option<String> fromString(String s)
s - A string to turn into an optional non-empty string.
public static F<String,Option<String>> fromString()
|
Copyright Tony Morris 2008 This software is released under an open source BSD licence. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||