Package fj.data
Class Option<A>
- java.lang.Object
-
- fj.data.Option<A>
-
- All Implemented Interfaces:
java.lang.Iterable<A>
- Direct Known Subclasses:
Option.None,Option.Some
public abstract class Option<A> extends java.lang.Object implements java.lang.Iterable<A>An optional value that may be none (no value) or some (a value). This type is a replacement for the use ofnullwith better type checks.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classOption.None<A>static classOption.Opticprivate static classOption.Some<A>
-
Field Summary
Fields Modifier and Type Field Description static F<java.lang.String,Option<java.lang.Byte>>parseByteA function that parses a string to a byte.static F<java.lang.String,Option<java.lang.Double>>parseDoubleA function that parses a string to a double.static F<java.lang.String,Option<java.lang.Float>>parseFloatA function that parses a string to a float.static F<java.lang.String,Option<java.lang.Integer>>parseIntA function that parses a string to an integer.static F<java.lang.String,Option<java.lang.Long>>parseLongA function that parses a string to a long.static F<java.lang.String,Option<java.lang.Short>>parseShortA function that parses a string to a short.
-
Constructor Summary
Constructors Modifier Constructor Description privateOption()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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,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.<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.<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.<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)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>
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>
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> Option<B>bind(F<A,Option<B>> f)Binds the given function across the element of this 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$>
Option<P6<A,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>
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)<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)booleanequals(java.lang.Object other)booleanexists(F<A,java.lang.Boolean> f)Returnstrueis this optional value has a value and the given predicate function holds on that value,falseotherwise.Option<A>filter(F<A,java.lang.Boolean> f)Filters elements from this optional value by returning only elements which producetruewhen the given function is applied to them.booleanforall(F<A,java.lang.Boolean> f)Returnstrueif this optional value has no value, or the predicate holds for the given predicate function,falseotherwise.Unitforeach(F<A,Unit> f)Performs a side-effect for the value of this optional value.voidforeachDoEffect(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.inthashCode()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.booleanisNone()Returnsfalseif this optional value has a value,trueotherwise.static <A> F<Option<A>,java.lang.Boolean>isNone_()A first-class version of the isNone method.booleanisSome()Returnstrueif this optional value has a value,falseotherwise.static <A> F<Option<A>,java.lang.Boolean>isSome_()A first-class version of the isSome method.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.intlength()Returns the length of this optional value; 1 if there is a value, 0 otherwise.<B,C>
Option<C>liftM2(Option<B> ob, F2<A,B,C> f)Lift the function of arity-2 through options.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.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> Option<T>none()Constructs an optional value that has no value.static <T> F<T,Option<T>>none_()<B> Boption(B b, F<A,B> f)Performs a reduction on this optional value using the given arguments.<B> Boption(F0<B> b, F<A,B> f)Performs a reduction on this optional value using the given arguments.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.Option<A>orElse(Option<A> o)Returns this optional value if there is one, otherwise, returns the argument optional value.Option<A>orElse(F0<Option<A>> o)Returns this optional value if there is one, otherwise, returns the argument optional value.AorSome(A a)Returns the value of this optional value or the given argument.AorSome(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 a list 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 <E,A>
Option<Validation<E,A>>sequence(Validation<E,Option<A>> a)Sequence a validation through the option monad.static <L,B>
Either<L,Option<B>>sequenceEither(Option<Either<L,B>> option)Sequence the given option and collect the output on the right side of an either.static <R,B>
Either<Option<B>,R>sequenceEitherLeft(Option<Either<B,R>> option)Sequence the given option and collect the output on the left side of an either.static <L,B>
Either<L,Option<B>>sequenceEitherRight(Option<Either<L,B>> option)Sequence the given option and collect the output on the right side of an either.static <C,B>
F<C,Option<B>>sequenceF(Option<F<C,B>> option)Sequence the given option and collect the output as a function.static <B> IO<Option<B>>sequenceIO(Option<IO<B>> option)Sequence the given option and collect the output as an IO.static <B> List<Option<B>>sequenceList(Option<List<B>> option)Sequence the given option and collect the output as an list.static <B> Option<Option<B>>sequenceOption(Option<Option<B>> option)Sequence the given option and collect the output as an option.static <B> P1<Option<B>>sequenceP1(Option<P1<B>> option)Sequence the given option and collect the output as a P1.static <B> Seq<Option<B>>sequenceSeq(Option<Seq<B>> option)Sequence the given option and collect the output as a seq.static <B> Set<Option<B>>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.static <B> Stream<Option<B>>sequenceStream(Option<Stream<B>> option)Sequence the given option and collect the output as a stream.static <B> Trampoline<Option<B>>sequenceTrampoline(Option<Trampoline<B>> option)Sequence the given option and collect the output as a trampoline.static <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.static <T> F<T,Option<T>>some_()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 inLeftif no value, or the value inRight.<X> Either<X,A>toEither(X x)Returns an either projection of this optional value; the given argument inLeftif no value, or the value inRight.List<A>toList()Returns a list projection of this optional value.AtoNull()Returns the value from this optional value, or if there is no value, returnsnull.Stream<A>toStream()Returns a stream projection of this optional value.java.lang.StringtoString()<X> Validation<X,A>toValidation(X x)<L,B>
Either<L,Option<B>>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.<R,B>
Either<Option<B>,R>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.<L,B>
Either<L,Option<B>>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.<C,B>
F<C,Option<B>>traverseF(F<A,F<C,B>> f)Traverse this option with the given function and collect the output as a function.<B> IO<Option<B>>traverseIO(F<A,IO<B>> f)Traverse this option with the given function and collect the output as an IO.<B> List<Option<B>>traverseList(F<A,List<B>> f)Traverse this option with the given function and collect the output as a list.<B> Option<Option<B>>traverseOption(F<A,Option<B>> f)Traverse this option with the given function and collect the output as an option.<B> P1<Option<B>>traverseP1(F<A,P1<B>> f)Traverse this option with the given function and collect the output as a P1.<B> Seq<Option<B>>traverseSeq(F<A,Seq<B>> f)Traverse this option with the given function and collect the output a seq.<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)Traverse this option with the given function and collect the output as a set; use the given ord to order the set.<B> Stream<Option<B>>traverseStream(F<A,Stream<B>> f)Traverse this option with the given function and collect the output as a stream.<B> Trampoline<Option<B>>traverseTrampoline(F<A,Trampoline<B>> f)Traverse this option with the given function and collect the output as a trampoline.<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.AvalueE(F0<java.lang.String> message)Returns the value of this optional value or fails with the given message.AvalueE(java.lang.String message)Returns the value of this optional value or fails with the given message.
-
-
-
Field Detail
-
parseByte
public static final F<java.lang.String,Option<java.lang.Byte>> parseByte
A function that parses a string to a byte.
-
parseDouble
public static final F<java.lang.String,Option<java.lang.Double>> parseDouble
A function that parses a string to a double.
-
parseFloat
public static final F<java.lang.String,Option<java.lang.Float>> parseFloat
A function that parses a string to a float.
-
parseInt
public static final F<java.lang.String,Option<java.lang.Integer>> parseInt
A function that parses a string to an integer.
-
parseLong
public static final F<java.lang.String,Option<java.lang.Long>> parseLong
A function that parses a string to a long.
-
-
Method Detail
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
iterator
public final java.util.Iterator<A> iterator()
Returns an iterator for this optional value. This method exists to permit the use in afor-each loop.- Specified by:
iteratorin interfacejava.lang.Iterable<A>- Returns:
- A iterator for this optional value.
-
some
public abstract A 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_
public static <A> F<Option<A>,java.lang.Boolean> 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_
public static <A> F<Option<A>,java.lang.Boolean> 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
public final <B> B option(B b, F<A,B> f)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
public final <B> B option(F0<B> b, F<A,B> f)
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
public final A orSome(F0<A> a)
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
public final A orSome(A a)
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
public final A valueE(F0<java.lang.String> message)
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
public final A valueE(java.lang.String message)
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
public final <B> Option<B> map(F<A,B> f)
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
public static <A,B> F<F<A,B>,F<Option<A>,Option<B>>> map()
A first-class map function.- Returns:
- A function that maps a given function across a given optional value.
-
foreach
public final Unit foreach(F<A,Unit> f)
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
public final void foreachDoEffect(Effect1<A> f)
Performs a side-effect for the value of this optional value.- Parameters:
f- The side-effect to perform for the given element.
-
filter
public final Option<A> filter(F<A,java.lang.Boolean> f)
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
public final <B> Option<B> bind(F<A,Option<B>> f)
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
public final <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.- 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
public final <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.- 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,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.- 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,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)
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,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.- 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,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.- 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,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.- 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
public final <B,C,D> Option<P4<A,B,C,D>> bindProduct(Option<B> ob, Option<C> oc, Option<D> od)
-
bindProduct
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)
-
bindProduct
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)
-
bindProduct
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)
-
bindProduct
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)
-
sequence
public final <B> Option<B> sequence(Option<B> o)
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
public static final <L,B> Either<L,Option<B>> sequenceEither(Option<Either<L,B>> option)
Sequence the given option and collect the output on the right side of an either.- Type Parameters:
B- the type of the right valueL- the type of the left value- Parameters:
option- the given option- Returns:
- the either
-
sequenceEitherLeft
public static final <R,B> Either<Option<B>,R> sequenceEitherLeft(Option<Either<B,R>> option)
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
public static final <L,B> Either<L,Option<B>> sequenceEitherRight(Option<Either<L,B>> option)
Sequence the given option and collect the output on the right side of an either.- Type Parameters:
B- the type of the right valueL- the type of the left value- Parameters:
option- the given option- Returns:
- the either
-
sequenceF
public static final <C,B> F<C,Option<B>> sequenceF(Option<F<C,B>> option)
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
public static final <B> IO<Option<B>> sequenceIO(Option<IO<B>> option)
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
public static final <B> List<Option<B>> sequenceList(Option<List<B>> option)
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
public static final <B> Option<Option<B>> sequenceOption(Option<Option<B>> option)
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
public static final <B> P1<Option<B>> sequenceP1(Option<P1<B>> option)
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
public static final <B> Seq<Option<B>> sequenceSeq(Option<Seq<B>> option)
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
public static final <B> Set<Option<B>> 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.- Type Parameters:
B- the type of the set value- Parameters:
ord- the given ordoption- the given option- Returns:
- the either
-
sequenceStream
public static final <B> Stream<Option<B>> sequenceStream(Option<Stream<B>> option)
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
public static final <B> Trampoline<Option<B>> sequenceTrampoline(Option<Trampoline<B>> option)
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
public final <L,B> Either<L,Option<B>> 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.- Type Parameters:
L- the type of the left valueB- the type of the right value- Parameters:
f- the given function- Returns:
- the either
-
traverseEitherLeft
public final <R,B> Either<Option<B>,R> 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.- Type Parameters:
R- the type of the left valueB- the type of the right value- Parameters:
f- the given function- Returns:
- the either
-
traverseEitherRight
public final <L,B> Either<L,Option<B>> 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.- Type Parameters:
L- the type of the left valueB- the type of the right value- Parameters:
f- the given function- Returns:
- the either
-
traverseF
public final <C,B> F<C,Option<B>> traverseF(F<A,F<C,B>> f)
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
public final <B> IO<Option<B>> traverseIO(F<A,IO<B>> f)
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
public final <B> List<Option<B>> traverseList(F<A,List<B>> f)
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
public final <B> Option<Option<B>> traverseOption(F<A,Option<B>> f)
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
public final <B> P1<Option<B>> traverseP1(F<A,P1<B>> f)
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
public final <B> Seq<Option<B>> traverseSeq(F<A,Seq<B>> f)
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
public final <B> Set<Option<B>> 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.- Type Parameters:
B- the type of the set value- Parameters:
ord- the given ordf- the given function- Returns:
- the set
-
traverseStream
public final <B> Stream<Option<B>> traverseStream(F<A,Stream<B>> f)
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
public 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.- Type Parameters:
B- the type of the trampoline value- Parameters:
f- the given function- Returns:
- the trampoline
-
traverseValidation
public 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.- Type Parameters:
E- the type of the failure valueB- the type of the success value- Parameters:
f- the given function- Returns:
- the validation
-
apply
public final <B> Option<B> apply(Option<F<A,B>> of)
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
public final Option<A> orElse(F0<Option<A>> o)
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
public final Option<A> orElse(Option<A> o)
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
public final <X> Either<X,A> toEither(F0<X> x)
Returns an either projection of this optional value; the given argument inLeftif 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
public final <X> Either<X,A> toEither(X x)
Returns an either projection of this optional value; the given argument inLeftif 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
public final <X> Validation<X,A> toValidation(X x)
-
toEither
public static <A,X> F<Option<A>,F<X,Either<X,A>>> 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
public final List<A> toList()
Returns a list projection of this optional value.- Returns:
- A list projection of this optional value.
-
toStream
public final Stream<A> toStream()
Returns a stream projection of this optional value.- Returns:
- A stream projection of this optional value.
-
toArray
public final Array<A> toArray()
Returns an array projection of this optional value.- Returns:
- An array projection of this optional value.
-
toArray
public final Array<A> toArray(java.lang.Class<A[]> c)
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
public final A[] array(java.lang.Class<A[]> c)
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
public final A 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
public final boolean forall(F<A,java.lang.Boolean> f)
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
public final boolean exists(F<A,java.lang.Boolean> f)
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
public final boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
toCollection
public final java.util.Collection<A> toCollection()
Projects an immutable collection of this optional value.- Returns:
- An immutable collection of this optional value.
-
some
public static <T> Option<T> some(T t)
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
public static <T> Option<T> none()
Constructs an optional value that has no value.- Returns:
- An optional value that has no value.
-
fromNull
public static <T> Option<T> fromNull(T t)
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
public static <T> F<T,Option<T>> fromNull()
Turns an unsafe nullable value into a safe optional value. Ift == nullthen return none, otherwise, return the given value in some.- Returns:
- If
t == nullthen return none, otherwise, return it in some.
-
option_
public static final <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.- 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
public static <A> Option<A> join(Option<Option<A>> o)
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
public static <A> Option<List<A>> sequence(List<Option<A>> a)
Sequence a list through the option monad.- Parameters:
a- The list of option to sequence.- Returns:
- The option of list after sequencing.
-
sequence
public static <E,A> Option<Validation<E,A>> sequence(Validation<E,Option<A>> a)
Sequence a validation through the option monad.- Parameters:
a- The validation of option to sequence.- Returns:
- The option of validation after sequencing.
-
iif
public 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.- 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
public 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.- 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
public 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.- 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
public static <A> F2<F<A,java.lang.Boolean>,A,Option<A>> 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
public static <A> List<A> somes(List<Option<A>> as)
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
public static <A> Stream<A> somes(Stream<Option<A>> as)
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
public 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.- 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()
- Overrides:
hashCodein classjava.lang.Object
-
fromString
public 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.- Returns:
- a function that transforms a string to an optional non-empty string, or no value if the string is empty.
-
fromSome
public 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.- Returns:
- A function that takes an optional value to a value or errors if there is no value.
-
liftM2
public 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.- Parameters:
f- A function to promote.- Returns:
- The given function promoted to operate on options.
-
liftM2
public final <B,C> Option<C> liftM2(Option<B> ob, F2<A,B,C> f)
Lift the function of arity-2 through options.- Parameters:
f- A function to lift.- Returns:
- An optional result.
-
bind
public static <A,B> F<F<A,Option<B>>,F<Option<A>,Option<B>>> bind()
First-class bind function.- Returns:
- A function that binds a given function across an option with a final join.
-
-