public interface Option<T> extends Serializable
someOrNullNoneOf(Object)
static factory method). You can think of this class as OneOf1OrNone.Modifier and Type | Interface and Description |
---|---|
static class |
Option.Some<T>
Represents the presence of a value, even if that value is null.
|
Modifier and Type | Field and Description |
---|---|
static Option |
NONE
None is a singleton and this is its only instance.
|
Modifier and Type | Method and Description |
---|---|
T |
get()
Return the value wrapped in this Option.
|
T |
getOrElse(T t)
If this is Some, return the value wrapped in this Option.
|
boolean |
isSome()
Is this Some?
|
<U> U |
match(Fn1<T,U> has,
Fn0<U> hasNot)
Pass in a function to execute if its Some and another to execute if its None.
|
static <T> Option<T> |
none()
Calling this instead of referring to NONE directly can make the type infrencer happy.
|
static <T> Option<T> |
of(T t)
Deprecated.
|
static <T> Option<T> |
some(T t)
Public static factory method for constructing the Some Option.
|
static <T> Option<T> |
someOrNullNoneOf(T t)
Construct an option, but if t is null, make it None instead of Some.
|
<U> Option<U> |
then(Fn1<T,Option<U>> f)
If this is Some, Apply the given function, else return None.
|
static final Option NONE
T get()
T getOrElse(T t)
<U> Option<U> then(Fn1<T,Option<U>> f)
boolean isSome()
<U> U match(Fn1<T,U> has, Fn0<U> hasNot)
static <T> Option<T> none()
@Deprecated static <T> Option<T> of(T t)
some(Object)
be better for your purposes? For some reason, this returns none
if you pass it a none. This is like flatmapping Options. Is this good for chaining or
is this just weird? If the first, I'm going to rename it flatten() or flatmap() or something.
If the second, it should be deleted. Remember, you also have Or
for chaining or
returning an error which is probably a better choice than Option for that kind of thing.static <T> Option<T> some(T t)
static <T> Option<T> someOrNullNoneOf(T t)
Copyright © 2017. All rights reserved.