Class Options

java.lang.Object
io.atlassian.fugue.Options

public class Options extends Object
Utility methods for working with options.
Since:
1.1
  • Constructor Details

    • Options

      private Options()
  • Method Details

    • find

      public static <A> Option<A> find(Iterable<Option<A>> options)
      Find the first option that isDefined, or if there aren't any, then none.
      Type Parameters:
      A - the contained type
      Parameters:
      options - an Iterable of options to search through
      Returns:
      the first defined option, or none if there aren't any
    • upcast

      public static <AA, A extends AA> Option<AA> upcast(Option<A> o)
      Upcasts an option of type A to an option of its super type AA.
      Type Parameters:
      AA - the super type of the contained type
      A - a A object.
      Parameters:
      o - the source option
      Returns:
      an option of the super type
      Since:
      2.0
    • lift

      public static <A,B> Function<Option<A>, Option<B>> lift(Function<A,B> f)
      Lifts a function that takes an A and returns a B into a function that takes an option of A and returns an option of B.
      Type Parameters:
      A - the input type of the original function
      B - the result type of the original function
      Parameters:
      f - the original function to be lifted, must not be null
      Returns:
      a function that takes an option of type A and returns an option of type B
      Since:
      2.0
    • lift

      public static <A,B> Function<Function<A,B>, Function<Option<A>, Option<B>>> lift()
      Returns a function that will lift a function that takes an A and returns a B into a function that takes an option of A and returns an option of B.
      Type Parameters:
      A - the input type of the function that can be lifted
      B - the result type of the function that can be lifted
      Returns:
      a function that can lift a function of input type A and result type B into Option
      Since:
      2.0
    • lift

      public static <A> Predicate<Option<A>> lift(Predicate<? super A> pred)
      Lifts a predicate that takes an A into a predicate that takes an option of A.
      Type Parameters:
      A - the input type of the predicate
      Parameters:
      pred - the original predicate to be lifted, must not be null
      Returns:
      a predicate that takes an option of type A
      Since:
      2.2
    • ap

      public static <A,B> Option<B> ap(Option<A> oa, Option<Function<A,B>> of)
      Applies an option of A to an option of a function with input type A and result type B and return an option of B.
      Type Parameters:
      A - the input type of the function wrapped in the option 'of'
      B - the result type of the function wrapped in the option 'of'
      Parameters:
      oa - an option of the argument to the function
      of - an option of a function that takes an A and returns a B
      Returns:
      an option of B
      Since:
      2.0
    • lift2

      public static <A,B,C> BiFunction<Option<A>, Option<B>, Option<C>> lift2(BiFunction<A,B,C> f2)
      Lifts a function that takes an A and a B and returns a C into a function that takes an option of A and an option of B and returns an option of C.
      Type Parameters:
      A - the input type of the first argument of the original function
      B - the input type of the second argument of the original function
      C - the result type of the original function
      Parameters:
      f2 - the original function to be lifted
      Returns:
      a function that takes an option of type A and an option of B and returns an option of type C
      Since:
      2.0
    • lift2

      public static <A,B,C> Function<BiFunction<A,B,C>, BiFunction<Option<A>, Option<B>, Option<C>>> lift2()
      Returns a function that will lift a function that takes an A and a B and returns a C into a function that takes an option of A and an option of B and returns an option of C.
      Type Parameters:
      A - the input type of the first argument of the function that can be lifted
      B - the input type of the second argument of the function that can be lifted
      C - the result type of the function that can be lifted
      Returns:
      a function that can lift a function of input type A and B and result type C into Option
      Since:
      2.0
    • filterNone

      public static <A> Iterable<Option<A>> filterNone(Iterable<Option<A>> options)
      Filter out undefined options.
      Type Parameters:
      A - the contained type
      Parameters:
      options - many options that may or may not be defined
      Returns:
      the filtered options
    • flatten

      public static <A> Iterable<A> flatten(Iterable<Option<A>> options)
      Flattens an Iterable of options into an iterable of the things, filtering out any nones.
      Type Parameters:
      A - the contained type
      Parameters:
      options - the iterable of options
      Returns:
      an Iterable of the contained type
    • toOption

      public static <A> Function<A, Option<A>> toOption()
      Function for wrapping values in a Some or None.
      Type Parameters:
      A - the contained type
      Returns:
      a Function to wrap values
      Since:
      3.0
    • nullSafe

      public static <A,B> Function<A, Option<B>> nullSafe(Function<A,B> nullProducing)
      Turn a null producing function into one that returns an option instead.
      Type Parameters:
      A - input type to the function.
      B - output type of the function.
      Parameters:
      nullProducing - the function that may return null
      Returns:
      a function that turns nulls into None, and wraps non-null values in Some.
      Since:
      3.0