public interface Maybe<T>
extends java.lang.Iterable<T>
get()
, but it has or()
:).
Slightly better implementation of Optional, as there are no IF blocks all over the class.Modifier and Type | Interface and Description |
---|---|
static class |
Maybe.Just<T> |
Modifier and Type | Method and Description |
---|---|
void |
consumeJust(java.util.function.Consumer<T> consumer)
Consumes value if present.
|
Maybe<T> |
filter(java.util.function.Predicate<? super T> mapping) |
<U> Maybe<U> |
flatMap(java.util.function.Function<? super T,Maybe<U>> mapper)
Flat map.
|
boolean |
isJust()
Returns
true if value is present. |
boolean |
isNothing()
Returns
false if value is not present. |
static <T> Maybe<T> |
just(T theValue)
Returns a JUST>
|
<U> Maybe<U> |
map(java.util.function.Function<? super T,? extends U> mapper)
Map.
|
<V> V |
maybe(V defaultValue,
java.util.function.Function<T,V> function)
Takes a default value and a function.
|
static <T> Maybe<T> |
nothing()
Returns a NOTHING.
|
static <T> Maybe<T> |
of(java.util.Optional<T> optionalValue) |
static <T> Maybe<T> |
of(T value)
Static factory for Maybe.
|
java.util.Optional<T> |
optional()
Converts Maybe to the Java Optional.
|
Maybe<T> |
or(Maybe<T> maybe)
Use give maybe if this one is NOTHING.
|
Maybe<T> |
or(java.util.function.Supplier<? extends Maybe<? extends T>> supplier)
Use supplied value if this one is NOTHING.
|
Maybe<T> |
or(T otherValue)
Use a maybe of given value if this one is NOTHING.
|
java.util.stream.Stream<T> |
stream()
Returns empty or single-element stream.
|
static <T> Maybe<T> of(T value)
static <T> Maybe<T> of(java.util.Optional<T> optionalValue)
boolean isJust()
true
if value is present.boolean isNothing()
false
if value is not present.<V> V maybe(V defaultValue, java.util.function.Function<T,V> function)
void consumeJust(java.util.function.Consumer<T> consumer)
java.util.stream.Stream<T> stream()
Maybe<T> or(java.util.function.Supplier<? extends Maybe<? extends T>> supplier)
java.util.Optional<T> optional()
static <T> Maybe<T> nothing()
static <T> Maybe<T> just(T theValue)
Copyright © 2003-present Jodd Team