Class Option<A>
java.lang.Object
fj.data.Option<A>
- All Implemented Interfaces:
Iterable<A>
- Direct Known Subclasses:
Option.None, Option.Some
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classstatic final classprivate 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 booleanfinal booleanReturnstrueis this optional value has a value and the given predicate function holds on that value,falseotherwise.Filters elements from this optional value by returning only elements which producetruewhen the given function is applied to them.final booleanReturnstrueif this optional value has no value, or the predicate holds for the given predicate function,falseotherwise.final UnitPerforms a side-effect for the value of this optional value.final voidforeachDoEffect(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 inthashCode()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 booleanisNone()Returnsfalseif this optional value has a value,trueotherwise.isNone_()A first-class version of the isNone method.final booleanisSome()Returnstrueif this optional value has a value,falseotherwise.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 intlength()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> BPerforms a reduction on this optional value using the given arguments.final <B> BPerforms 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 AReturns the value of this optional value or the given argument.final AReturns 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 Asome()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 inLeftif no value, or the value inRight.toEither(X x) Returns an either projection of this optional value; the given argument inLeftif no value, or the value inRight.toList()Returns a list projection of this optional value.final AtoNull()Returns the value from this optional value, or if there is no value, returnsnull.toStream()Returns a stream projection of this optional value.final StringtoString()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 AReturns the value of this optional value or fails with the given message.final AReturns the value of this optional value or fails with the given message.Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
parseByte
-
parseDouble
-
parseFloat
-
parseInt
-
parseLong
-
parseShort
-
-
Constructor Details
-
Option
private Option()
-
-
Method Details
-
toString
-
iterator
-
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()Returnstrueif this optional value has a value,falseotherwise.- Returns:
trueif this optional value has a value,falseotherwise.
-
isNone
public final boolean isNone()Returnsfalseif this optional value has a value,trueotherwise.- Returns:
falseif this optional value has a value,trueotherwise.
-
isSome_
-
isNone_
-
option
-
option
-
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
-
orSome
-
valueE
-
valueE
-
map
-
map
-
foreach
-
foreachDoEffect
-
filter
Filters elements from this optional value by returning only elements which producetruewhen 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
-
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
-
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
-
sequenceIO
-
sequenceList
-
sequenceOption
-
sequenceP1
-
sequenceSeq
-
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
-
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
-
traverseIO
-
traverseList
-
traverseOption
-
traverseP1
-
traverseSeq
-
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
-
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
-
toEither
-
toValidation
-
toEither
-
toList
-
toStream
-
toArray
-
toArray
-
array
-
toNull
Returns the value from this optional value, or if there is no value, returnsnull. This is intended for interfacing with APIs that expect anullfor non-existence.- Returns:
- This optional value or
nullif there is no value.
-
forall
Returnstrueif this optional value has no value, or the predicate holds for the given predicate function,falseotherwise.- Parameters:
f- the predicate function to test on the value of this optional value.- Returns:
trueif this optional value has no value, or the predicate holds for the given predicate function,falseotherwise.
-
exists
Returnstrueis this optional value has a value and the given predicate function holds on that value,falseotherwise.- Parameters:
f- the predicate function to test on the value of this optional value.- Returns:
trueis this optional value has a value and the given predicate function holds on that value,falseotherwise.
-
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 == nullthen return none, otherwise, return the given value in some.- Parameters:
t- The unsafe nullable value.- Returns:
- If
t == nullthen return none, otherwise, return it in some.
-
fromNull
-
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
-
sequence
-
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
-
somes
-
somes
-
fromString
-
hashCode
-
fromString
-
fromSome
-
liftM2
-
liftM2
-
bind
-
join
-