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

public abstract class Option<A> extends Object implements Iterable<A>
An optional value that may be none (no value) or some (a value). This type is a replacement for the use of null with better type checks.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
     
    static final class 
     
    private static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final F<String,Option<Byte>>
    A function that parses a string to a byte.
    static final F<String,Option<Double>>
    A function that parses a string to a double.
    static final F<String,Option<Float>>
    A function that parses a string to a float.
    static final F<String,Option<Integer>>
    A function that parses a string to an integer.
    static final F<String,Option<Long>>
    A function that parses a string to a long.
    static final F<String,Option<Short>>
    A function that parses a string to a short.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final <B> Option<B>
    apply(Option<F<A,B>> of)
    Performs function application within an optional value (applicative functor pattern).
    final A[]
    array(Class<A[]> c)
    Returns an array from this optional value.
    static <A, B> F<F<A,Option<B>>,F<Option<A>,Option<B>>>
    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$>
    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.
    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.
    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.
    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.
    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.
    final <B> Option<P2<A,B>>
     
    final <B, C> Option<P3<A,B,C>>
    bindProduct(Option<B> ob, Option<C> oc)
     
    final <B, C, D> Option<P4<A,B,C,D>>
    bindProduct(Option<B> ob, Option<C> oc, Option<D> od)
     
    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)
     
    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)
     
    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)
     
    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)
     
    final boolean
    equals(Object other)
     
    final boolean
    Returns true is this optional value has a value and the given predicate function holds on that value, false otherwise.
    final Option<A>
    Filters elements from this optional value by returning only elements which produce true when the given function is applied to them.
    final boolean
    Returns true 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
    Performs a side-effect for the value of this optional value.
    static <T> F<T,Option<T>>
    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>
    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.
    static Option<String>
    Returns an optional non-empty string, or no value if the given string is empty.
    final int
     
    static <A> F2<F<A,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,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.
    final boolean
    Returns false if this optional value has a value, true otherwise.
    static <A> F<Option<A>,Boolean>
    A first-class version of the isNone method.
    final boolean
    Returns true if this optional value has a value, false otherwise.
    static <A> F<Option<A>,Boolean>
    A first-class version of the isSome method.
    final Iterator<A>
    Returns an iterator for this optional value.
    static <A> F<Option<Option<A>>,Option<A>>
    First-class join function.
    static <A> Option<A>
    Joins the given optional value of optional value using a bind operation.
    final int
    Returns the length of this optional value; 1 if there is a value, 0 otherwise.
    final <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.
    final <B> Option<B>
    map(F<A,B> f)
    Maps the given function across this optional value.
    static <T> Option<T>
    Constructs an optional value that has no value.
    static <T> F<T,Option<T>>
     
    final <B> B
    option(B b, F<A,B> f)
    Performs a reduction on this optional value using the given arguments.
    final <B> B
    option(F0<B> b, F<A,B> f)
    Performs a reduction on this optional value using the given arguments.
    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.
    final Option<A>
    Returns this optional value if there is one, otherwise, returns the argument optional value.
    final Option<A>
    Returns this optional value if there is one, otherwise, returns the argument optional value.
    final A
    orSome(A a)
    Returns the value of this optional value or the given argument.
    final A
    orSome(F0<A> a)
    Returns the value of this optional value or the given argument.
    static <A> Option<List<A>>
    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 a validation through the option monad.
    static final <L, B> Either<L,Option<B>>
    Sequence the given option and collect the output on the right side of an either.
    static final <R, B> Either<Option<B>,R>
    Sequence the given option and collect the output on the left side of an either.
    static final <L, B> Either<L,Option<B>>
    Sequence the given option and collect the output on the right side of an either.
    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.
    static final <B> IO<Option<B>>
    sequenceIO(Option<IO<B>> option)
    Sequence the given option and collect the output as an IO.
    static final <B> List<Option<B>>
    sequenceList(Option<List<B>> option)
    Sequence the given option and collect the output as an list.
    static final <B> Option<Option<B>>
    Sequence the given option and collect the output as an option.
    static final <B> P1<Option<B>>
    sequenceP1(Option<P1<B>> option)
    Sequence the given option and collect the output as a P1.
    static final <B> Seq<Option<B>>
    sequenceSeq(Option<Seq<B>> option)
    Sequence the given option and collect the output as a seq.
    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.
    static final <B> Stream<Option<B>>
    Sequence the given option and collect the output as a stream.
    static final <B> Trampoline<Option<B>>
    Sequence the given option and collect the output as a trampoline.
    static final <E, B> Validation<E,Option<B>>
    Sequence the given option and collect the output as a validation.
    abstract A
    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>>
     
    static <A> List<A>
    somes(List<Option<A>> as)
    Returns all the values in the given list.
    static <A> Stream<A>
    Returns all the values in the given stream.
    final Array<A>
    Returns an array projection of this optional value.
    final Array<A>
    toArray(Class<A[]> c)
    Returns an array projection of this optional value.
    final Collection<A>
    Projects an immutable collection of this optional value.
    static <A, X> F<Option<A>,F<X,Either<X,A>>>
    A first-class version of the toEither method.
    final <X> Either<X,A>
    toEither(F0<X> x)
    Returns an either projection of this optional value; the given argument in Left if no value, or the value in Right.
    final <X> Either<X,A>
    toEither(X x)
    Returns an either projection of this optional value; the given argument in Left if no value, or the value in Right.
    final List<A>
    Returns a list projection of this optional value.
    final A
    Returns the value from this optional value, or if there is no value, returns null.
    final Stream<A>
    Returns a stream projection of this optional value.
    final String
     
    final <X> Validation<X,A>
     
    final <L, B> Either<L,Option<B>>
    Traverse this option with the given function and collect the output on the right side of an either.
    final <R, B> Either<Option<B>,R>
    Traverse this option with the given function and collect the output on the left side of an either.
    final <L, B> Either<L,Option<B>>
    Traverse this option with the given function and collect the output on the right side of an either.
    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.
    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.
    final <B> List<Option<B>>
    Traverse this option with the given function and collect the output as a list.
    final <B> Option<Option<B>>
    Traverse this option with the given function and collect the output as an option.
    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.
    final <B> Seq<Option<B>>
    traverseSeq(F<A,Seq<B>> f)
    Traverse this option with the given function and collect the output a seq.
    final <B> F2<Ord<B>,F<A,Set<B>>,Set<Option<B>>>
     
    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.
    final <B> Stream<Option<B>>
    Traverse this option with the given function and collect the output as a stream.
    final <B> Trampoline<Option<B>>
    Traverse this option with the given function and collect the output as a trampoline.
    final <E, B> Validation<E,Option<B>>
    Traverse this option with the given function and collect the output as a validation.
    final A
    valueE(F0<String> message)
    Returns the value of this optional value or fails with the given message.
    final A
    valueE(String message)
    Returns the value of this optional value or fails with the given message.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • parseByte

      public static final F<String,Option<Byte>> parseByte
      A function that parses a string to a byte.
    • parseDouble

      public static final F<String,Option<Double>> parseDouble
      A function that parses a string to a double.
    • parseFloat

      public static final F<String,Option<Float>> parseFloat
      A function that parses a string to a float.
    • parseInt

      public static final F<String,Option<Integer>> parseInt
      A function that parses a string to an integer.
    • parseLong

      public static final F<String,Option<Long>> parseLong
      A function that parses a string to a long.
    • parseShort

      public static final F<String,Option<Short>> parseShort
      A function that parses a string to a short.
  • Constructor Details

    • Option

      private Option()
  • Method Details

    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • iterator

      public final Iterator<A> iterator()
      Returns an iterator for this optional value. This method exists to permit the use in a for-each loop.
      Specified by:
      iterator in interface 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()
      Returns true 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()
      Returns false if this optional value has a value, true otherwise.
      Returns:
      false if this optional value has a value, true otherwise.
    • isSome_

      public static <A> F<Option<A>,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>,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<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(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,Boolean> f)
      Filters elements from this optional value by returning only elements which produce true 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

      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> Option<P2<A,B>> bindProduct(Option<B> ob)
    • bindProduct

      public final <B, C> Option<P3<A,B,C>> bindProduct(Option<B> ob, Option<C> oc)
    • 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:
      L - the type of the left value
      B - the type of the right 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 value
      B - 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:
      L - the type of the left value
      B - the type of the right 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 value
      B - 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 ord
      option - 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 value
      B - 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 value
      B - 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 value
      B - 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 value
      B - 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 value
      B - 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 ord
      f - 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 value
      B - the type of the success value
      Parameters:
      f - the given function
      Returns:
      the validation
    • traverseSet

      public final <B> F2<Ord<B>,F<A,Set<B>>,Set<Option<B>>> traverseSet()
    • 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 in Left if no value, or the value in Right.
      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 in Left if no value, or the value in Right.
      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(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(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, returns null. This is intended for interfacing with APIs that expect a null for non-existence.
      Returns:
      This optional value or null if there is no value.
    • forall

      public final boolean forall(F<A,Boolean> f)
      Returns true if this optional value has no value, or the predicate holds for the given predicate function, false otherwise.
      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

      public final boolean exists(F<A,Boolean> f)
      Returns true is this optional value has a value and the given predicate function holds on that value, false otherwise.
      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

      public final boolean equals(Object other)
      Overrides:
      equals in class Object
    • toCollection

      public final Collection<A> toCollection()
      Projects an immutable collection of this optional value.
      Returns:
      An immutable collection of this optional value.
    • some_

      public static <T> F<T,Option<T>> some_()
    • 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> F<T,Option<T>> none_()
    • 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. If t == 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

      public static <T> F<T,Option<T>> fromNull()
      Turns an unsafe nullable value into a safe optional value. If t == null then return none, otherwise, return the given value in some.
      Returns:
      If t == null then 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,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,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<String> fromString(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:
      hashCode in class Object
    • fromString

      public static F<String,Option<String>> fromString()
      Returns a function that transforms a string to an optional non-empty string, or no value if the string is empty.
      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.
    • join

      public static <A> F<Option<Option<A>>,Option<A>> join()
      First-class join function.
      Returns:
      A function that joins an Option of an Option to make a single Option.