|
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. |
||||||||
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). |
|
static
|
bind()
First-class bind function. |
|
|
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. |
|
|
bindProduct(Option<B> ob)
|
|
|
bindProduct(Option<B> ob,
Option<C> oc)
|
|
|
bindProduct(Option<B> ob,
Option<C> oc,
Option<D> od)
|
|
|
bindProduct(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe)
|
|
|
bindProduct(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
Option<F$> of)
|
|
|
bindProduct(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
Option<F$> of,
Option<G> og)
|
|
|
bindProduct(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
Option<F$> of,
Option<G> og,
Option<H> oh)
|
|
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
|
fromSome()
Returns a function that takes an optional value to a value or errors if there is no 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. |
|
static
|
isNone_()
A first-class version of the isNone method. |
|
boolean |
isNone()
Returns false if this optional value has a value, true otherwise. |
|
static
|
isSome_()
A first-class version of the isSome method. |
|
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()
First-class join function. |
|
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. |
|
static
|
liftM2(F<A,F<B,C>> f)
Promotes a function of arity-2 so that it operates over options. |
|
static
|
map()
A first-class map function. |
|
|
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(P1<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. |
|
static
|
somes(Stream<Option<A>> as)
Returns all the values in the given stream. |
|
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. |
|
static
|
toEither()
A first-class version of the toEither method. |
|
|
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. |
|
A |
toNull()
Returns the value from this optional value, or if there is no value, returns null . |
|
Stream<A> |
toStream()
Returns a stream projection of this optional value. |
|
A |
valueE(P1<String> message)
Returns the value of this optional value or fails with the given message. |
|
A |
valueE(String message)
Returns the value of this optional value or fails with the given message. |
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 static <A> F<Option<A>,Boolean> isSome_()
public static <A> F<Option<A>,Boolean> isNone_()
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 <B> B option(P1<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 A valueE(P1<String> message)
message
- The message to fail with if this optional value has no value.
public A valueE(String message)
message
- The message to fail with if this optional value has no value.
public <B> Option<B> map(F<A,B> f)
f
- The function to map across this optional value.
public static <A,B> F<F<A,B>,F<Option<A>,Option<B>>> map()
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<P2<A,B>> bindProduct(Option<B> ob)
public <B,C> Option<P3<A,B,C>> bindProduct(Option<B> ob, Option<C> oc)
public <B,C,D> Option<P4<A,B,C,D>> bindProduct(Option<B> ob, Option<C> oc, Option<D> od)
public <B,C,D,E> Option<P5<A,B,C,D,E>> bindProduct(Option<B> ob, Option<C> oc, Option<D> od, Option<E> oe)
public <B,C,D,E,F$> Option<P6<A,B,C,D,E,F$>> bindProduct(Option<B> ob, Option<C> oc, Option<D> od, Option<E> oe, Option<F$> of)
public <B,C,D,E,F$,G> Option<P7<A,B,C,D,E,F$,G>> bindProduct(Option<B> ob, Option<C> oc, Option<D> od, Option<E> oe, Option<F$> of, Option<G> og)
public <B,C,D,E,F$,G,H> Option<P8<A,B,C,D,E,F$,G,H>> bindProduct(Option<B> ob, Option<C> oc, Option<D> od, Option<E> oe, Option<F$> of, Option<G> og, Option<H> oh)
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 static <A,X> F<Option<A>,F<X,Either<X,A>>> toEither()
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 A toNull()
null
.
This is intended for interfacing with APIs that expect a null
for non-existence.
null
if there is no value.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 <A> Stream<A> somes(Stream<Option<A>> as)
as
- The stream 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()
public static <A> F<Option<A>,A> fromSome()
public static <A,B,C> F<Option<A>,F<Option<B>,Option<C>>> liftM2(F<A,F<B,C>> f)
f
- A function to promote.
public static <A,B> F<F<A,Option<B>>,F<Option<A>,Option<B>>> bind()
public static <A> F<Option<Option<A>>,Option<A>> join()
|
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. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |