Package fj.data
Class Option<A>
java.lang.Object
fj.data.Option<A>
- All Implemented Interfaces:
Iterable<A>
- Direct Known Subclasses:
Option.None
,Option.Some
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
static final class
private static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionA function that parses a string to a byte.A function that parses a string to a double.A function that parses a string to a float.A function that parses a string to an integer.A function that parses a string to a long.A function that parses a string to a short. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <B> Option
<B> Performs function application within an optional value (applicative functor pattern).final A[]
Returns an array from this optional value.bind()
First-class bind function.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) Binds the given function across the element of this optional value and the given optional value with a final join.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) Binds the given function across the element of this optional value and the given optional value with a final join.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) Binds the given function across the element of this optional value and the given optional value with a final join.final <B,
C, D, E, F$>
Option<F$> Binds the given function across the element of this optional value and the given optional value with a final join.final <B,
C, D, E>
Option<E> Binds the given function across the element of this optional value and the given optional value with a final join.final <B,
C, D> Option <D> Binds the given function across the element of this optional value and the given optional value with a final join.final <B,
C> Option <C> Binds the given function across the element of this optional value and the given optional value with a final join.final <B> Option
<B> Binds the given function across the element of this 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, Option<G> og, Option<H> oh) final boolean
final boolean
Returnstrue
is this optional value has a value and the given predicate function holds on that value,false
otherwise.Filters elements from this optional value by returning only elements which producetrue
when the given function is applied to them.final boolean
Returnstrue
if this optional value has no value, or the predicate holds for the given predicate function,false
otherwise.final Unit
Performs a side-effect for the value of this optional value.final void
foreachDoEffect
(Effect1<A> f) Performs a side-effect for the value of this optional value.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.fromSome()
Returns a function that takes an optional value to a value or errors if there is no value.Returns a function that transforms a string to an optional non-empty string, or no value if the string is empty.fromString
(String s) Returns an optional non-empty string, or no value if the given string is empty.final int
hashCode()
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> 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> Returns an optional value that has a value of the given argument, if the given predicate holds on that argument, otherwise, returns no value.final boolean
isNone()
Returnsfalse
if this optional value has a value,true
otherwise.isNone_()
A first-class version of the isNone method.final boolean
isSome()
Returnstrue
if this optional value has a value,false
otherwise.isSome_()
A first-class version of the isSome method.iterator()
Returns an iterator for this optional value.join()
First-class join function.static <A> Option
<A> Joins the given optional value of optional value using a bind operation.final int
length()
Returns the length of this optional value; 1 if there is a value, 0 otherwise.final <B,
C> Option <C> Lift the function of arity-2 through options.Promotes a function of arity-2 so that it operates over options.map()
A first-class map function.final <B> Option
<B> Maps the given function across this optional value.static <T> Option
<T> none()
Constructs an optional value that has no value.none_()
final <B> B
Performs a reduction on this optional value using the given arguments.final <B> B
Performs a reduction on this optional value using the given arguments.First-class catamorphism for Option: return a function that will performs a reduction on an optional value using the given arguments.Returns this optional value if there is one, otherwise, returns the argument optional value.Returns this optional value if there is one, otherwise, returns the argument optional value.final A
Returns the value of this optional value or the given argument.final A
Returns the value of this optional value or the given argument.Sequence a list through the option monad.final <B> Option
<B> Performs a bind across the optional value, but ignores the element value in the function.static <E,
A> Option <Validation<E, A>> sequence
(Validation<E, Option<A>> a) Sequence a validation through the option monad.sequenceEither
(Option<Either<L, B>> option) Sequence the given option and collect the output on the right side of an either.sequenceEitherLeft
(Option<Either<B, R>> option) Sequence the given option and collect the output on the left side of an either.sequenceEitherRight
(Option<Either<L, B>> option) Sequence the given option and collect the output on the right side of an either.Sequence the given option and collect the output as a function.sequenceIO
(Option<IO<B>> option) Sequence the given option and collect the output as an IO.sequenceList
(Option<List<B>> option) Sequence the given option and collect the output as an list.sequenceOption
(Option<Option<B>> option) Sequence the given option and collect the output as an option.sequenceP1
(Option<P1<B>> option) Sequence the given option and collect the output as a P1.sequenceSeq
(Option<Seq<B>> option) Sequence the given option and collect the output as a seq.sequenceSet
(Ord<B> ord, Option<Set<B>> option) Sequence the given option and collect the output as a set; use the given ord to order the set.sequenceStream
(Option<Stream<B>> option) Sequence the given option and collect the output as a stream.static final <B> Trampoline
<Option<B>> sequenceTrampoline
(Option<Trampoline<B>> option) Sequence the given option and collect the output as a trampoline.static final <E,
B> Validation <E, Option<B>> sequenceValidation
(Option<Validation<E, B>> option) Sequence the given option and collect the output as a validation.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.some_()
static <A> List
<A> Returns all the values in the given list.static <A> Stream
<A> Returns all the values in the given stream.toArray()
Returns an array projection of this optional value.Returns an array projection of this optional value.final Collection
<A> Projects an immutable collection of this optional value.toEither()
A first-class version of the toEither method.Returns an either projection of this optional value; the given argument inLeft
if no value, or the value inRight
.toEither
(X x) Returns an either projection of this optional value; the given argument inLeft
if no value, or the value inRight
.toList()
Returns a list projection of this optional value.final A
toNull()
Returns the value from this optional value, or if there is no value, returnsnull
.toStream()
Returns a stream projection of this optional value.final String
toString()
final <X> Validation
<X, A> toValidation
(X x) traverseEither
(F<A, Either<L, B>> f) Traverse this option with the given function and collect the output on the right side of an either.traverseEitherLeft
(F<A, Either<B, R>> f) Traverse this option with the given function and collect the output on the left side of an either.traverseEitherRight
(F<A, Either<L, B>> f) Traverse this option with the given function and collect the output on the right side of an either.Traverse this option with the given function and collect the output as a function.traverseIO
(F<A, IO<B>> f) Traverse this option with the given function and collect the output as an IO.traverseList
(F<A, List<B>> f) Traverse this option with the given function and collect the output as a list.traverseOption
(F<A, Option<B>> f) Traverse this option with the given function and collect the output as an option.traverseP1
(F<A, P1<B>> f) Traverse this option with the given function and collect the output as a P1.traverseSeq
(F<A, Seq<B>> f) Traverse this option with the given function and collect the output a seq.traverseSet
(Ord<B> ord, F<A, Set<B>> f) Traverse this option with the given function and collect the output as a set; use the given ord to order the set.traverseStream
(F<A, Stream<B>> f) Traverse this option with the given function and collect the output as a stream.final <B> Trampoline
<Option<B>> traverseTrampoline
(F<A, Trampoline<B>> f) Traverse this option with the given function and collect the output as a trampoline.final <E,
B> Validation <E, Option<B>> traverseValidation
(F<A, Validation<E, B>> f) Traverse this option with the given function and collect the output as a validation.final A
Returns the value of this optional value or fails with the given message.final A
Returns the value of this optional value or fails with the given message.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
parseByte
A function that parses a string to a byte. -
parseDouble
A function that parses a string to a double. -
parseFloat
A function that parses a string to a float. -
parseInt
A function that parses a string to an integer. -
parseLong
A function that parses a string to a long. -
parseShort
A function that parses a string to a short.
-
-
Constructor Details
-
Option
private Option()
-
-
Method Details
-
toString
-
iterator
Returns an iterator for this optional value. This method exists to permit the use in afor
-each loop. -
some
Returns the value from this optional value, or fails if there is no value.- Returns:
- The value from this optional value, or fails if there is no value.
-
isSome
public final boolean isSome()Returnstrue
if this optional value has a value,false
otherwise.- Returns:
true
if this optional value has a value,false
otherwise.
-
isNone
public final boolean isNone()Returnsfalse
if this optional value has a value,true
otherwise.- Returns:
false
if this optional value has a value,true
otherwise.
-
isSome_
A first-class version of the isSome method.- Returns:
- A function that returns true if a given optional value has a value, otherwise false.
-
isNone_
A first-class version of the isNone method.- Returns:
- A function that returns false if a given optional value has a value, otherwise true.
-
option
Performs a reduction on this optional value using the given arguments.- Parameters:
b
- The value to return if this optional value has no value.f
- The function to apply to the value of this optional value.- Returns:
- A reduction on this optional value.
-
option
Performs a reduction on this optional value using the given arguments.- Parameters:
b
- The value to return if this optional value has no value.f
- The function to apply to the value of this optional value.- Returns:
- A reduction on this optional value.
-
length
public final int length()Returns the length of this optional value; 1 if there is a value, 0 otherwise.- Returns:
- The length of this optional value; 1 if there is a value, 0 otherwise.
-
orSome
Returns the value of this optional value or the given argument.- Parameters:
a
- The argument to return if this optiona value has no value.- Returns:
- The value of this optional value or the given argument.
-
orSome
Returns the value of this optional value or the given argument.- Parameters:
a
- The argument to return if this optiona value has no value.- Returns:
- The value of this optional value or the given argument.
-
valueE
Returns the value of this optional value or fails with the given message.- Parameters:
message
- The message to fail with if this optional value has no value.- Returns:
- The value of this optional value if there there is one.
-
valueE
Returns the value of this optional value or fails with the given message.- Parameters:
message
- The message to fail with if this optional value has no value.- Returns:
- The value of this optional value if there there is one.
-
map
Maps the given function across this optional value.- Parameters:
f
- The function to map across this optional value.- Returns:
- A new optional value after the given function has been applied to its element.
-
map
A first-class map function.- Returns:
- A function that maps a given function across a given optional value.
-
foreach
Performs a side-effect for the value of this optional value.- Parameters:
f
- The side-effect to perform for the given element.- Returns:
- The unit value.
-
foreachDoEffect
Performs a side-effect for the value of this optional value.- Parameters:
f
- The side-effect to perform for the given element.
-
filter
Filters elements from this optional value by returning only elements which producetrue
when the given function is applied to them.- Parameters:
f
- The predicate function to filter on.- Returns:
- A new optional value whose value matches the given predicate if it has one.
-
bind
Binds the given function across the element of this optional value with a final join.- Parameters:
f
- The function to apply to the element of this optional value.- Returns:
- A new optional value after performing the map, then final join.
-
bind
Binds the given function across the element of this optional value and the given optional value with a final join.- Parameters:
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.- Returns:
- A new optional value after performing the map, then final join.
-
bind
Binds the given function across the element of this optional value and the given optional value with a final join.- Parameters:
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.- Returns:
- A new optional value after performing the map, then final join.
-
bind
public final <B,C, Option<E> bindD, E> (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.- Parameters:
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.- Returns:
- A new optional value after performing the map, then final join.
-
bind
public final <B,C, Option<F$> bindD, E, F$> (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.- Parameters:
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.- Returns:
- A new optional value after performing the map, then final join.
-
bind
public final <B,C, Option<G> bindD, E, F$, G> (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.- Parameters:
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.- Returns:
- A new optional value after performing the map, then final join.
-
bind
public final <B,C, Option<H> bindD, E, F$, G, H> (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.- Parameters:
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.- Returns:
- A new optional value after performing the map, then final join.
-
bind
public final <B,C, Option<I> bindD, E, F$, G, H, I> (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.- Parameters:
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.- Returns:
- A new optional value after performing the map, then final join.
-
bindProduct
-
bindProduct
-
bindProduct
-
bindProduct
-
bindProduct
-
bindProduct
-
bindProduct
-
sequence
Performs a bind across the optional value, but ignores the element value in the function.- Parameters:
o
- The optional value to apply in the final join.- Returns:
- A new optional value after the final join.
-
sequenceEither
Sequence the given option and collect the output on the right side of an either.- Type Parameters:
L
- the type of the left valueB
- the type of the right value- Parameters:
option
- the given option- Returns:
- the either
-
sequenceEitherLeft
Sequence the given option and collect the output on the left side of an either.- Type Parameters:
R
- the type of the right valueB
- the type of the left value- Parameters:
option
- the given option- Returns:
- the either
-
sequenceEitherRight
Sequence the given option and collect the output on the right side of an either.- Type Parameters:
L
- the type of the left valueB
- the type of the right value- Parameters:
option
- the given option- Returns:
- the either
-
sequenceF
Sequence the given option and collect the output as a function.- Type Parameters:
C
- the type of the input valueB
- the type of the output value- Parameters:
option
- the given option- Returns:
- the either
-
sequenceIO
Sequence the given option and collect the output as an IO.- Type Parameters:
B
- the type of the IO value- Parameters:
option
- the given option- Returns:
- the IO
-
sequenceList
Sequence the given option and collect the output as an list.- Type Parameters:
B
- the type of the list value- Parameters:
option
- the given option- Returns:
- the list
-
sequenceOption
Sequence the given option and collect the output as an option.- Type Parameters:
B
- the type of the option value- Parameters:
option
- the given option- Returns:
- the option
-
sequenceP1
Sequence the given option and collect the output as a P1.- Type Parameters:
B
- the type of the P1 value- Parameters:
option
- the given option- Returns:
- the P1
-
sequenceSeq
Sequence the given option and collect the output as a seq.- Type Parameters:
B
- the type of the seq value- Parameters:
option
- the given option- Returns:
- the seq
-
sequenceSet
Sequence the given option and collect the output as a set; use the given ord to order the set.- Type Parameters:
B
- the type of the set value- Parameters:
ord
- the given ordoption
- the given option- Returns:
- the either
-
sequenceStream
Sequence the given option and collect the output as a stream.- Type Parameters:
B
- the type of the stream value- Parameters:
option
- the given option- Returns:
- the stream
-
sequenceTrampoline
Sequence the given option and collect the output as a trampoline.- Type Parameters:
B
- the type of the stream value- Parameters:
option
- the given trampoline- Returns:
- the stream
-
sequenceValidation
public static final <E,B> Validation<E,Option<B>> sequenceValidation(Option<Validation<E, B>> option) Sequence the given option and collect the output as a validation.- Type Parameters:
E
- the type of the failure valueB
- the type of the success value- Parameters:
option
- the given option- Returns:
- the validation
-
traverseEither
Traverse this option with the given function and collect the output on the right side of an either.- Type Parameters:
L
- the type of the left valueB
- the type of the right value- Parameters:
f
- the given function- Returns:
- the either
-
traverseEitherLeft
Traverse this option with the given function and collect the output on the left side of an either.- Type Parameters:
R
- the type of the left valueB
- the type of the right value- Parameters:
f
- the given function- Returns:
- the either
-
traverseEitherRight
Traverse this option with the given function and collect the output on the right side of an either.- Type Parameters:
L
- the type of the left valueB
- the type of the right value- Parameters:
f
- the given function- Returns:
- the either
-
traverseF
Traverse this option with the given function and collect the output as a function.- Type Parameters:
C
- the type of the input valueB
- the type of the output value- Parameters:
f
- the given function- Returns:
- the function
-
traverseIO
Traverse this option with the given function and collect the output as an IO.- Type Parameters:
B
- the type of the IO value- Parameters:
f
- the given function- Returns:
- the IO
-
traverseList
Traverse this option with the given function and collect the output as a list.- Type Parameters:
B
- the type of the list value- Parameters:
f
- the given function- Returns:
- the list
-
traverseOption
Traverse this option with the given function and collect the output as an option.- Type Parameters:
B
- the type of the option value- Parameters:
f
- the given function- Returns:
- the option
-
traverseP1
Traverse this option with the given function and collect the output as a P1.- Type Parameters:
B
- the type of the P1 value- Parameters:
f
- the given function- Returns:
- the P1
-
traverseSeq
Traverse this option with the given function and collect the output a seq.- Type Parameters:
B
- the type of the seq value- Parameters:
f
- the given function- Returns:
- the seq
-
traverseSet
Traverse this option with the given function and collect the output as a set; use the given ord to order the set.- Type Parameters:
B
- the type of the set value- Parameters:
ord
- the given ordf
- the given function- Returns:
- the set
-
traverseStream
Traverse this option with the given function and collect the output as a stream.- Type Parameters:
B
- the type of the stream value- Parameters:
f
- the given function- Returns:
- the stream
-
traverseTrampoline
Traverse this option with the given function and collect the output as a trampoline.- Type Parameters:
B
- the type of the trampoline value- Parameters:
f
- the given function- Returns:
- the trampoline
-
traverseValidation
Traverse this option with the given function and collect the output as a validation.- Type Parameters:
E
- the type of the failure valueB
- the type of the success value- Parameters:
f
- the given function- Returns:
- the validation
-
traverseSet
-
apply
Performs function application within an optional value (applicative functor pattern).- Parameters:
of
- The optional value of functions to apply.- Returns:
- A new optional value after applying the given optional value of functions through this optional value.
-
orElse
Returns this optional value if there is one, otherwise, returns the argument optional value.- Parameters:
o
- The optional value to return if this optional value has no value.- Returns:
- This optional value if there is one, otherwise, returns the argument optional value.
-
orElse
Returns this optional value if there is one, otherwise, returns the argument optional value.- Parameters:
o
- The optional value to return if this optional value has no value.- Returns:
- This optional value if there is one, otherwise, returns the argument optional value.
-
toEither
Returns an either projection of this optional value; the given argument inLeft
if no value, or the value inRight
.- Parameters:
x
- The value to return in left if this optional value has no value.- Returns:
- An either projection of this optional value.
-
toEither
Returns an either projection of this optional value; the given argument inLeft
if no value, or the value inRight
.- Parameters:
x
- The value to return in left if this optional value has no value.- Returns:
- An either projection of this optional value.
-
toValidation
-
toEither
A first-class version of the toEither method.- Returns:
- A function that returns an either projection of a given optional value, given a value to return in left.
-
toList
Returns a list projection of this optional value.- Returns:
- A list projection of this optional value.
-
toStream
Returns a stream projection of this optional value.- Returns:
- A stream projection of this optional value.
-
toArray
Returns an array projection of this optional value.- Returns:
- An array projection of this optional value.
-
toArray
Returns an array projection of this optional value.- Parameters:
c
- The class type of the array to return.- Returns:
- An array projection of this optional value.
-
array
Returns an array from this optional value.- Parameters:
c
- The class type of the array to return.- Returns:
- An array from this optional value.
-
toNull
Returns the value from this optional value, or if there is no value, returnsnull
. This is intended for interfacing with APIs that expect anull
for non-existence.- Returns:
- This optional value or
null
if there is no value.
-
forall
Returnstrue
if this optional value has no value, or the predicate holds for the given predicate function,false
otherwise.- Parameters:
f
- the predicate function to test on the value of this optional value.- Returns:
true
if this optional value has no value, or the predicate holds for the given predicate function,false
otherwise.
-
exists
Returnstrue
is this optional value has a value and the given predicate function holds on that value,false
otherwise.- Parameters:
f
- the predicate function to test on the value of this optional value.- Returns:
true
is this optional value has a value and the given predicate function holds on that value,false
otherwise.
-
equals
-
toCollection
Projects an immutable collection of this optional value.- Returns:
- An immutable collection of this optional value.
-
some_
-
some
Constructs an optional value that has a value of the given argument.- Parameters:
t
- The value for the returned optional value.- Returns:
- An optional value that has a value of the given argument.
-
none_
-
none
Constructs an optional value that has no value.- Returns:
- An optional value that has no value.
-
fromNull
Turns an unsafe nullable value into a safe optional value. Ift == null
then return none, otherwise, return the given value in some.- Parameters:
t
- The unsafe nullable value.- Returns:
- If
t == null
then return none, otherwise, return it in some.
-
fromNull
Turns an unsafe nullable value into a safe optional value. Ift == null
then return none, otherwise, return the given value in some.- Returns:
- If
t == null
then return none, otherwise, return it in some.
-
option_
First-class catamorphism for Option: return a function that will performs a reduction on an optional value using the given arguments.- Parameters:
none
- The value to return if this optional value has no value.some
- The function to apply to the value of this optional value.- Returns:
- the reducing function.
-
join
Joins the given optional value of optional value using a bind operation.- Parameters:
o
- The optional value of optional value to join.- Returns:
- A new optional value that is the join of the given optional value.
-
sequence
Sequence a list through the option monad.- Parameters:
a
- The list of option to sequence.- Returns:
- The option of list after sequencing.
-
sequence
Sequence a validation through the option monad.- Parameters:
a
- The validation of option to sequence.- Returns:
- The option of validation after sequencing.
-
iif
Returns an optional value that has a value of the given argument, if the given predicate holds on that argument, otherwise, returns no value.- Parameters:
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.- Returns:
- an optional value that has a value of the given argument, if the given predicate holds on that argument, otherwise, returns no value.
-
iif
Returns an optional value that has a value of the given argument if the given boolean is true, otherwise, returns no value.- Parameters:
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.- Returns:
- An optional value that has a value of the given argument if the given boolean is true, otherwise, returns no value.
-
iif
Returns an optional value that has a value of the given argument if the given boolean is true, otherwise, returns no value.- Parameters:
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.- Returns:
- An optional value that has a value of the given argument if the given boolean is true, otherwise, returns no value.
-
iif
First-class version of the iif function.- Returns:
- a function that returns an optional value that has a value of the given argument, if the given predicate holds on that argument, or no value otherwise.
-
somes
Returns all the values in the given list.- Parameters:
as
- The list of potential values to get actual values from.- Returns:
- All the values in the given list.
-
somes
Returns all the values in the given stream.- Parameters:
as
- The stream of potential values to get actual values from.- Returns:
- All the values in the given stream.
-
fromString
Returns an optional non-empty string, or no value if the given string is empty.- Parameters:
s
- A string to turn into an optional non-empty string.- Returns:
- an optional non-empty string, or no value if the given string is empty.
-
hashCode
public final int hashCode() -
fromString
Returns a function that transforms a string to an optional non-empty string, or no value if the string is empty.- Returns:
- a function that transforms a string to an optional non-empty string, or no value if the string is empty.
-
fromSome
Returns a function that takes an optional value to a value or errors if there is no value.- Returns:
- A function that takes an optional value to a value or errors if there is no value.
-
liftM2
Promotes a function of arity-2 so that it operates over options.- Parameters:
f
- A function to promote.- Returns:
- The given function promoted to operate on options.
-
liftM2
Lift the function of arity-2 through options.- Parameters:
f
- A function to lift.- Returns:
- An optional result.
-
bind
First-class bind function.- Returns:
- A function that binds a given function across an option with a final join.
-
join
First-class join function.- Returns:
- A function that joins an Option of an Option to make a single Option.
-