public abstract class Option<A>
extends java.lang.Object
implements java.lang.Iterable<A>
null
with better type checks.Modifier and Type | Class and Description |
---|---|
static class |
Option.Optic |
Modifier and Type | Field and Description |
---|---|
static F<java.lang.String,Option<java.lang.Byte>> |
parseByte
A function that parses a string to a byte.
|
static F<java.lang.String,Option<java.lang.Double>> |
parseDouble
A function that parses a string to a double.
|
static F<java.lang.String,Option<java.lang.Float>> |
parseFloat
A function that parses a string to a float.
|
static F<java.lang.String,Option<java.lang.Integer>> |
parseInt
A function that parses a string to an integer.
|
static F<java.lang.String,Option<java.lang.Long>> |
parseLong
A function that parses a string to a long.
|
static F<java.lang.String,Option<java.lang.Short>> |
parseShort
A function that parses a string to a short.
|
Modifier and Type | Method and Description |
---|---|
<B> Option<B> |
apply(Option<F<A,B>> of)
Performs function application within an optional value (applicative functor pattern).
|
A[] |
array(java.lang.Class<A[]> c)
Returns an array from this optional value.
|
static <A,B> F<F<A,Option<B>>,F<Option<A>,Option<B>>> |
bind()
First-class bind function.
|
<B> Option<B> |
bind(F<A,Option<B>> f)
Binds the given function across the element of this optional value with a final join.
|
<B,C> Option<C> |
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.
|
<B,C,D> Option<D> |
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.
|
<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)
Binds the given function across the element of this optional value and the given optional value
with a final join.
|
<B,C,D,E,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)
Binds the given function across the element of this optional value and the given optional value
with a final join.
|
<B,C,D,E,F$,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)
Binds the given function across the element of this optional value and the given optional value
with a final join.
|
<B,C,D,E,F$,G,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)
Binds the given function across the element of this optional value and the given optional value
with a final join.
|
<B,C,D,E,F$,G,H,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)
Binds the given function across the element of this optional value and the given optional value
with a final join.
|
<B> Option<P2<A,B>> |
bindProduct(Option<B> ob) |
<B,C> Option<P3<A,B,C>> |
bindProduct(Option<B> ob,
Option<C> oc) |
<B,C,D> Option<P4<A,B,C,D>> |
bindProduct(Option<B> ob,
Option<C> oc,
Option<D> od) |
<B,C,D,E> Option<P5<A,B,C,D,E>> |
bindProduct(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe) |
<B,C,D,E,F$> |
bindProduct(Option<B> ob,
Option<C> oc,
Option<D> od,
Option<E> oe,
Option<F$> of) |
<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) |
<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) |
boolean |
equals(java.lang.Object other) |
boolean |
exists(F<A,java.lang.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,java.lang.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,java.lang.Boolean> f)
Returns
true if this optional value has no value, or the predicate holds for the
given predicate function, false otherwise. |
Unit |
foreach(F<A,Unit> f)
Performs a side-effect for the value of this optional value.
|
void |
foreachDoEffect(Effect1<A> f)
Performs a side-effect for the value of this optional value.
|
static <T> F<T,Option<T>> |
fromNull()
Turns an unsafe nullable value into a safe optional value.
|
static <T> Option<T> |
fromNull(T t)
Turns an unsafe nullable value into a safe optional value.
|
static <A> F<Option<A>,A> |
fromSome()
Returns a function that takes an optional value to a value or errors if there is no value.
|
static F<java.lang.String,Option<java.lang.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<java.lang.String> |
fromString(java.lang.String s)
Returns an optional non-empty string, or no value if the given string is empty.
|
int |
hashCode() |
static <A> F2<F<A,java.lang.Boolean>,A,Option<A>> |
iif()
First-class version of the iif function.
|
static <A> Option<A> |
iif(boolean p,
A a)
Returns an optional value that has a value of the given argument if the given boolean is true, otherwise, returns
no value.
|
static <A> Option<A> |
iif(boolean p,
F0<A> a)
Returns an optional value that has a value of the given argument if the given boolean is true, otherwise, returns
no value.
|
static <A> Option<A> |
iif(F<A,java.lang.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 <A> F<Option<A>,java.lang.Boolean> |
isNone_()
A first-class version of the isNone method.
|
boolean |
isNone()
Returns
false if this optional value has a value, true otherwise. |
static <A> F<Option<A>,java.lang.Boolean> |
isSome_()
A first-class version of the isSome method.
|
boolean |
isSome()
Returns
true if this optional value has a value, false otherwise. |
java.util.Iterator<A> |
iterator()
Returns an iterator for this optional value.
|
static <A> F<Option<Option<A>>,Option<A>> |
join()
First-class join function.
|
static <A> Option<A> |
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 if there is a value, 0 otherwise.
|
static <A,B,C> F<Option<A>,F<Option<B>,Option<C>>> |
liftM2(F<A,F<B,C>> f)
Promotes a function of arity-2 so that it operates over options.
|
<B,C> Option<C> |
liftM2(Option<B> ob,
F2<A,B,C> f)
Lift the function of arity-2 through options.
|
static <A,B> F<F<A,B>,F<Option<A>,Option<B>>> |
map()
A first-class map function.
|
<B> Option<B> |
map(F<A,B> f)
Maps the given function across this optional value.
|
static <T> F<T,Option<T>> |
none_() |
static <T> Option<T> |
none()
Constructs an optional value that has no value.
|
static <A,B> F<Option<A>,B> |
option_(B none,
F<A,B> some)
First-class catamorphism for Option: return a function that will performs
a reduction on an optional value using the given arguments.
|
<B> B |
option(B b,
F<A,B> f)
Performs a reduction on this optional value using the given arguments.
|
<B> B |
option(F0<B> b,
F<A,B> f)
Performs a reduction on this optional value using the given arguments.
|
Option<A> |
orElse(F0<Option<A>> o)
Returns this optional value if there is one, otherwise, returns the argument optional value.
|
Option<A> |
orElse(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(F0<A> a)
Returns the value of this optional value or the given argument.
|
static <A> Option<List<A>> |
sequence(List<Option<A>> a)
Sequence through the option monad.
|
<B> Option<B> |
sequence(Option<B> o)
Performs a bind across the optional value, but ignores the element value in the function.
|
static <T> F<T,Option<T>> |
some_() |
abstract A |
some()
Returns the value from this optional value, or fails if there is no value.
|
static <T> Option<T> |
some(T t)
Constructs an optional value that has a value of the given argument.
|
static <A> List<A> |
somes(List<Option<A>> as)
Returns all the values in the given list.
|
static <A> Stream<A> |
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(java.lang.Class<A[]> c)
Returns an array projection of this optional value.
|
java.util.Collection<A> |
toCollection()
Projects an immutable collection of this optional value.
|
static <A,X> F<Option<A>,F<X,Either<X,A>>> |
toEither()
A first-class version of the toEither method.
|
<X> Either<X,A> |
toEither(F0<X> x)
Returns an either projection of this optional value; the given argument in
Left if
no value, or the value in Right . |
<X> Either<X,A> |
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.
|
java.lang.String |
toString() |
<X> Validation<X,A> |
toValidation(X x) |
<L,B> Either<L,Option<B>> |
traverseEither(F<A,Either<L,B>> f) |
<B> IO<Option<B>> |
traverseIO(F<A,IO<B>> f) |
<B> List<Option<B>> |
traverseList(F<A,List<B>> f) |
<B> Option<Option<B>> |
traverseOption(F<A,Option<B>> f) |
<B> P1<Option<B>> |
traverseP1(F<A,P1<B>> f) |
<B> Seq<Option<B>> |
traverseSeq(F<A,Seq<B>> f) |
<B> F2<Ord<B>,F<A,Set<B>>,Set<Option<B>>> |
traverseSet() |
<B> Set<Option<B>> |
traverseSet(Ord<B> ord,
F<A,Set<B>> f) |
<B> Stream<Option<B>> |
traverseStream(F<A,Stream<B>> f) |
<E,B> Validation<E,Option<B>> |
traverseValidation(F<A,Validation<E,B>> f) |
A |
valueE(F0<java.lang.String> message)
Returns the value of this optional value or fails with the given message.
|
A |
valueE(java.lang.String message)
Returns the value of this optional value or fails with the given message.
|
public static final F<java.lang.String,Option<java.lang.Byte>> parseByte
public static final F<java.lang.String,Option<java.lang.Double>> parseDouble
public static final F<java.lang.String,Option<java.lang.Float>> parseFloat
public static final F<java.lang.String,Option<java.lang.Integer>> parseInt
public static final F<java.lang.String,Option<java.lang.Long>> parseLong
public final java.lang.String toString()
toString
in class java.lang.Object
public final java.util.Iterator<A> iterator()
for
-each loop.iterator
in interface java.lang.Iterable<A>
public abstract A some()
public final boolean isSome()
true
if this optional value has a value, false
otherwise.true
if this optional value has a value, false
otherwise.public final 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>,java.lang.Boolean> isSome_()
public static <A> F<Option<A>,java.lang.Boolean> isNone_()
public final <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 final <B> B option(F0<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 final int length()
public final A orSome(F0<A> a)
a
- The argument to return if this optiona value has no value.public final A orSome(A a)
a
- The argument to return if this optiona value has no value.public final A valueE(F0<java.lang.String> message)
message
- The message to fail with if this optional value has no value.public final A valueE(java.lang.String message)
message
- The message to fail with if this optional value has no value.public final <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 final Unit foreach(F<A,Unit> f)
f
- The side-effect to perform for the given element.public final void foreachDoEffect(Effect1<A> f)
f
- The side-effect to perform for the given element.public final Option<A> filter(F<A,java.lang.Boolean> f)
true
when the given function is applied to them.f
- The predicate function to filter on.public final <B> Option<B> bind(F<A,Option<B>> f)
f
- The function to apply to the element of this optional value.public final <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 final <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 final <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 final <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 final <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 final <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 final <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 final <B,C,D> Option<P4<A,B,C,D>> bindProduct(Option<B> ob, Option<C> oc, Option<D> od)
public final <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 final <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 final <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 final <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 final <B> Option<B> sequence(Option<B> o)
o
- The optional value to apply in the final join.public final <E,B> Validation<E,Option<B>> traverseValidation(F<A,Validation<E,B>> f)
public final <B> Option<B> apply(Option<F<A,B>> of)
of
- The optional value of functions to apply.public final Option<A> orElse(F0<Option<A>> o)
o
- The optional value to return if this optional value has no value.public final Option<A> orElse(Option<A> o)
o
- The optional value to return if this optional value has no value.public final <X> Either<X,A> toEither(F0<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 final <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 final <X> Validation<X,A> toValidation(X x)
public static <A,X> F<Option<A>,F<X,Either<X,A>>> toEither()
public final List<A> toList()
public final Stream<A> toStream()
public final Array<A> toArray()
public final Array<A> toArray(java.lang.Class<A[]> c)
c
- The class type of the array to return.public final A[] array(java.lang.Class<A[]> c)
c
- The class type of the array to return.public final A toNull()
null
.
This is intended for interfacing with APIs that expect a null
for non-existence.null
if there is no value.public final boolean forall(F<A,java.lang.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 final boolean exists(F<A,java.lang.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 final boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public final java.util.Collection<A> toCollection()
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 none, otherwise, return it in some.public static <T> F<T,Option<T>> fromNull()
t == null
then
return none, otherwise, return the given value in some.t == null
then return none, otherwise, return it in some.public static final <A,B> F<Option<A>,B> option_(B none, F<A,B> some)
none
- The value to return if this optional value has no value.some
- The function to apply to the value of this optional value.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,java.lang.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> Option<A> iif(boolean p, F0<A> a)
p
- The value to be true to return the given value.a
- the value to return in an optional value if the given boolean is true.public static <A> Option<A> iif(boolean p, A a)
p
- The value to be true to return the given value.a
- the value to return in an optional value if the given boolean is true.public static <A> F2<F<A,java.lang.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<java.lang.String> fromString(java.lang.String s)
s
- A string to turn into an optional non-empty string.public final int hashCode()
hashCode
in class java.lang.Object
public static F<java.lang.String,Option<java.lang.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 final <B,C> Option<C> liftM2(Option<B> ob, F2<A,B,C> f)
f
- A function to lift.public static <A,B> F<F<A,Option<B>>,F<Option<A>,Option<B>>> bind()