com.machinezoo.noexception.optional
Interface OptionalDoubleFunction<R>
-
- Type Parameters:
R
- seeDoubleFunction
- All Superinterfaces:
- DoubleFunction<Optional<R>>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface OptionalDoubleFunction<R> extends DoubleFunction<Optional<R>>
Variation ofDoubleFunction
that returnsOptional
instead of the raw value.OptionalDoubleFunction
is typically obtained fromExceptionHandler.fromDoubleFunction(DoubleFunction)
, in which case its return value is empty when the underlyingDoubleFunction
throws an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method and Description Optional<R>
apply(double value)
Variation ofDoubleFunction.apply(double)
that returnsOptional
.default DoubleFunction<R>
orElse(R result)
Convert thisOptionalDoubleFunction
to plainDoubleFunction
using default value.default DoubleFunction<R>
orElseGet(Supplier<R> source)
Convert thisOptionalDoubleFunction
to plainDoubleFunction
using fallbackSupplier
.
-
-
-
Method Detail
-
apply
Optional<R> apply(double value)
Variation ofDoubleFunction.apply(double)
that returnsOptional
. If thisOptionalDoubleFunction
is obtained fromExceptionHandler.fromDoubleFunction(DoubleFunction)
, theOptional
will be empty only if the underlyingDoubleFunction
throws. Otherwise the returnedOptional
just wraps the return value of underlyingDoubleFunction
(possiblynull
).- Specified by:
apply
in interfaceDoubleFunction<Optional<R>>
- Parameters:
value
- seeDoubleFunction.apply(double)
- Returns:
Optional
typically wrapping return value ofDoubleFunction.apply(double)
, or an emptyOptional
(typically signifying an exception)- See Also:
ExceptionHandler.fromDoubleFunction(DoubleFunction)
,DoubleFunction.apply(double)
-
orElse
default DoubleFunction<R> orElse(R result)
Convert thisOptionalDoubleFunction
to plainDoubleFunction
using default value. The returnedDoubleFunction
will unwrap present value from theOptional
if possible, or returnresult
if theOptional
is empty.- Parameters:
result
- default value to return instead of an emptyOptional
- Returns:
- plain
DoubleFunction
that either unwrapsOptional
or returns default value - See Also:
orElseGet(Supplier)
,Optional.orElse(Object)
-
orElseGet
default DoubleFunction<R> orElseGet(Supplier<R> source)
Convert thisOptionalDoubleFunction
to plainDoubleFunction
using fallbackSupplier
. The returnedDoubleFunction
will unwrap present value from theOptional
if possible, or fall back to callingsource
if theOptional
is empty.- Parameters:
source
-Supplier
to query for fallback value whenOptional
is empty- Returns:
- plain
DoubleFunction
that either unwrapsOptional
or falls back tosource
- See Also:
orElse(Object)
,Optional.orElseGet(Supplier)
-
-