|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Option<T>
An optional value inspired by sensible languages like Scala.
| Method Summary | ||
|---|---|---|
List<T> |
asList()
An empty list for None or an immutable list with
Some.get(). |
|
Option<T> |
filter(Filter<? super T> f)
If this option is Some and the given functor f
yields false on its value, return None. |
|
|
flatMap(Functor<? super T,Option<R>> mappingFunction)
|
|
void |
forEach(Command<? super T> command)
Apply the given Command to the option's value if it is not None. |
|
T |
getOrElse(Functor0<? extends T> generator)
If the option is Some return its value, otherwise return the
result of evaluating the generator expression. |
|
T |
getOrElse(T defaultValue)
If the option is Some return its value, otherwise return a
default value. |
|
|
map(Functor<? super T,R> mappingFunction)
If the option is Some, return a function applied to its
value, wrapped in a Some: , otherwise
return None. |
|
void |
match(Command<? super T> someCommand,
Command0 noneCommand)
A match strategy based on Commands. |
|
|
match(Functor<? super T,R1> someFunctor,
Functor0<R2> noneFunctor)
A match strategy based on Functors. |
|
void |
match(OptionMatcher<? super T> matcher)
Accept a for this Option. |
|
T |
unsafeGet()
Get the value returning null for None. |
|
| Methods inherited from interface java.lang.Iterable |
|---|
iterator |
| Method Detail |
|---|
void match(OptionMatcher<? super T> matcher)
Option.
In languages like Scala we can do this kind of thing:
x match {
case Some(s) => s
case None => "?"
}
In Java, such elegance is not possible so this method is actually a
Visitor implementation:
x.match(new OptionMatcher() {
public void caseSome(T value) { // excellent we can use the value }
public void caseNone() { // no value, deal with it }
});
void match(Command<? super T> someCommand,
Command0 noneCommand)
Some and None.
someCommand - a command that will receive the callback in the event that
Some is matchednoneCommand - a command that will receive the callback in the event that
None is matched
<R1,R2 extends R1> R1 match(Functor<? super T,R1> someFunctor,
Functor0<R2> noneFunctor)
someFunctor - the functor to execute if this Option is a SamenoneFunctor - the functor to execute if this Option is a None
List<T> asList()
None or an immutable list with
Some.get().
T getOrElse(Functor0<? extends T> generator)
Some return its value, otherwise return the
result of evaluating the generator expression.
generator - the default expression.T getOrElse(T defaultValue)
Some return its value, otherwise return a
default value.
<R> Option<R> map(Functor<? super T,R> mappingFunction)
Some, return a function applied to its
value, wrapped in a Some: Some(f(this.get)), otherwise
return None.
mappingFunction - the function to apply<R> Option<R> flatMap(Functor<? super T,Option<R>> mappingFunction)
void forEach(Command<? super T> command)
None. Do
nothing if it is None.
command - the Command to apply.Option<T> filter(Filter<? super T> f)
Some and the given functor f
yields false on its value, return None.
Otherwise return this option.
f - the filter used for testing.T unsafeGet()
null for None.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||