A - the contained typepublic interface Maybe<A> extends Iterable<A>, Effect.Applicant<A>
Note there are some methods suggested by this interface that cannot be expressed here as the return type cannot be expressed in Java's type system (due to the lack of higher-kinded types). These are for instance (where M is the implementing Maybe sub-type):
| Modifier and Type | Method and Description |
|---|---|
boolean |
exists(Predicate<? super A> p)
Whether this is
is defined and
applying the predicate to the contained value returns true. |
boolean |
forall(Predicate<? super A> p)
Returns
true if empty or the result of the
application of the given function to the value. |
A |
get()
Get the value if defined.
|
A |
getOr(Supplier<? extends A> supplier)
Get the value
if defined or call the supplier and
return its value if not. |
<B extends A> |
getOrElse(B other)
Get the value if defined, otherwise returns
other. |
A |
getOrElse(Supplier<? extends A> supplier)
Deprecated.
since 3.0
getOrElse(Supplier) is being replaced with
getOr(Supplier). In Java 8 type inference cannot disambiguate
between an overloaded method taking a generic A and the same method taking
a Supplier<A>. |
A |
getOrError(Supplier<String> msg)
Get the value or throws an error with the supplied message if not defined.
|
A |
getOrNull()
Get the value if defined or null if not.
|
<X extends Throwable> |
getOrThrow(Supplier<X> ifUndefined)
Get the value or throws the supplied throwable if not defined.
|
boolean |
isDefined()
If the type contains a value return true.
|
boolean |
isEmpty()
If the type does not contain a value return true.
|
Iterator<A> |
iterator()
Return an iterator for this type.
|
forEach, spliteratorforeachA get()
NoSuchElementException - if this is a none<B extends A> A getOrElse(B other)
other.B - default value typeother - value to return if this is emptyis defined, otherwise
returns otherA getOr(Supplier<? extends A> supplier)
if defined or call the supplier and
return its value if not. Replaces getOrElse(Supplier).
Get the value if defined or call the supplier and
return its value if not.supplier - called if this is emptySupplier@Deprecated A getOrElse(Supplier<? extends A> supplier)
getOrElse(Supplier) is being replaced with
getOr(Supplier). In Java 8 type inference cannot disambiguate
between an overloaded method taking a generic A and the same method taking
a Supplier<A>.if defined or call the supplier and
return its value if not.supplier - called if this is emptySupplierA getOrNull()
Although the use of null is discouraged, code written to use these must often interface with code that expects and returns nulls.
A getOrError(Supplier<String> msg)
Used when absolutely sure this is defined.
msg - the message for the error.<X extends Throwable> A getOrThrow(Supplier<X> ifUndefined) throws X extends Throwable
Used when absolutely sure this is defined.
X - exception typeifUndefined - the supplier of the throwable.X - the throwable the supplier creates if there is no value.X extends Throwableboolean isDefined()
true if this holds a value, false otherwise.boolean isEmpty()
true if this does not hold a value, false
otherwise.boolean exists(Predicate<? super A> p)
is defined and
applying the predicate to the contained value returns true.p - the predicate to test, must not be nulltrue if defined and the predicate returns true for the
contained value, false otherwise.Iterator<A> iterator()
iterator in interface Iterable<A>if
defined, or an empty one otherwise.boolean forall(Predicate<? super A> p)
true if empty or the result of the
application of the given function to the value.p - The predicate function to test on the contained value, must not be
nulltrue if no value or returns the result of the
application of the given function to the value.Copyright © 2017 Atlassian. All rights reserved.