Class Choice<T>
java.lang.Object
com.google.errorprone.refaster.Choice<T>
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 Summary
Modifier and TypeMethodDescriptionstatic <T> Choice
<T> any
(Collection<Choice<T>> choices) Returns a choice between any of the options from any of the specified choices.condition
(boolean condition) Returns this choice ifcondition
, otherwise the empty choice.static <T> Choice
<T> condition
(boolean condition, T t) Returns aChoice
witht
as an option ifcondition
, and no options otherwise.Filters the choices to those that satisfy the providedPredicate
.com.google.common.base.Optional
<T> first()
Returns the first valid option from thisChoice
.static <T> Choice
<T> from
(Collection<T> choices) static <T> Choice
<T> fromOptional
(com.google.common.base.Optional<T> optional) Returns a choice of the optional value, if it is present, or the empty choice if it is absent.iterator()
static <T> Choice
<T> none()
The emptyChoice
.static <T> Choice
<T> of
(T t) Returns aChoice
with only one option,t
.Returns a choice of the options from thisChoice
or fromother
.<R> Choice
<R> thenChoose
(com.google.common.base.Function<? super T, Choice<R>> function) Returns all the choices obtained by choosing from thisChoice
and then choosing from theChoice
yielded by this function on the result.<R> Choice
<R> thenOption
(com.google.common.base.Function<? super T, com.google.common.base.Optional<R>> function) Returns all the choices obtained by choosing from thisChoice
and yielding a presentOptional
.toString()
<R> Choice
<R> Maps the choices with the specified function.
-
Method Details
-
none
The emptyChoice
. -
of
Returns aChoice
with only one option,t
. -
condition
Returns aChoice
witht
as an option ifcondition
, and no options otherwise. -
fromOptional
Returns a choice of the optional value, if it is present, or the empty choice if it is absent. -
from
-
any
Returns a choice between any of the options from any of the specified choices. -
iterator
-
toString
-
first
Returns the first valid option from thisChoice
. -
thenChoose
Returns all the choices obtained by choosing from thisChoice
and then choosing from theChoice
yielded by this function on the result.The function may be applied lazily or immediately, at the discretion of the implementation.
This is the monadic bind for
Choice
. -
thenOption
public <R> Choice<R> thenOption(com.google.common.base.Function<? super T, com.google.common.base.Optional<R>> function) Returns all the choices obtained by choosing from thisChoice
and yielding a presentOptional
.The function may be applied lazily or immediately, at the discretion of the implementation.
-
transform
-
or
-
condition
-
condition
-