Class Choice<T>

java.lang.Object
com.google.errorprone.refaster.Choice<T>

public abstract class Choice<T> extends Object
A representation of a choice with zero or more options, which may be evaluated lazily or strictly.

This resembles the list monad in Haskell.

Author:
lowasser@google.com (Louis Wasserman)
  • Method Details

    • none

      public static <T> Choice<T> none()
      The empty Choice.
    • of

      public static <T> Choice<T> of(T t)
      Returns a Choice with only one option, t.
    • condition

      public static <T> Choice<T> condition(boolean condition, T t)
      Returns a Choice with t as an option if condition, and no options otherwise.
    • fromOptional

      public static <T> Choice<T> fromOptional(Optional<T> optional)
      Returns a choice of the optional value, if it is present, or the empty choice if it is absent.
    • from

      public static <T> Choice<T> from(Collection<T> choices)
    • iterator

      @ForOverride protected abstract Iterator<T> iterator()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • findFirst

      public Optional<T> findFirst()
      Returns the first valid option from this Choice.
    • flatMap

      public <R> Choice<R> flatMap(Function<? super T, Choice<R>> function)
      Returns all the choices obtained by choosing from this Choice and then choosing from the Choice yielded by this function on the result.

      The function may be applied lazily or immediately, at the discretion of the implementation.

    • mapIfPresent

      public <R> Choice<R> mapIfPresent(Function<? super T, Optional<R>> function)
      Returns all the choices obtained by choosing from this Choice and yielding a present Optional.

      The function may be applied lazily or immediately, at the discretion of the implementation.

    • map

      public <R> Choice<R> map(Function<? super T, R> function)
      Maps the choices with the specified function.
    • concat

      public Choice<T> concat(Choice<T> other)
      Returns a choice of the options from this Choice or from other.
    • filter

      public Choice<T> filter(Predicate<? super T> predicate)
      Filters the choices to those that satisfy the provided Predicate.