R
- see LongFunction
@FunctionalInterface public interface OptionalLongFunction<R> extends LongFunction<Optional<R>>
LongFunction
that returns Optional
instead of the raw value. OptionalLongFunction
is typically obtained from ExceptionHandler.fromLongFunction(LongFunction)
, in which case its return value is empty when the underlying LongFunction
throws an exception. See noexception tutorial.
Modifier and Type | Method and Description |
---|---|
Optional<R> |
apply(long value)
Variation of LongFunction.apply(long) that returns Optional .
|
default LongFunction<R> |
orElse(R result)
Converts this OptionalLongFunction to plain LongFunction using default value.
|
default LongFunction<R> |
orElseGet(Supplier<R> source)
|
Optional<R> apply(long value)
LongFunction.apply(long)
that returns Optional
. If this OptionalLongFunction
is obtained from ExceptionHandler.fromLongFunction(LongFunction)
, the Optional
will be empty only if the underlying LongFunction
throws. Otherwise the returned Optional
just wraps the return value of underlying LongFunction
(possibly null
).
apply
in interface LongFunction<Optional<R>>
value
- see LongFunction.apply(long)
Optional
typically wrapping return value of LongFunction.apply(long)
, or an empty Optional
(typically signifying an exception)
ExceptionHandler.fromLongFunction(LongFunction)
, LongFunction.apply(long)
default LongFunction<R> orElse(R result)
OptionalLongFunction
to plain LongFunction
using default value. The returned LongFunction
will unwrap present value from the Optional
if possible, or return result
if the Optional
is empty.
result
- default value to return instead of an empty Optional
LongFunction
that either unwraps Optional
or returns default value
orElseGet(Supplier)
, Optional.orElse(Object)
default LongFunction<R> orElseGet(Supplier<R> source)
OptionalLongFunction
to plain LongFunction
using fallback Supplier
. The returned LongFunction
will unwrap present value from the Optional
if possible, or fall back to calling source
if the Optional
is empty.
source
- Supplier
to query for fallback value when Optional
is empty
LongFunction
that either unwraps Optional
or falls back to source
orElse(Object)
, Optional.orElseGet(Supplier)
Copyright © 2017–2020 Robert Važan. All rights reserved.