Module com.machinezoo.noexception
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 ofDoubleFunctionthat returnsOptionalinstead of the raw value.OptionalDoubleFunctionis typically obtained fromExceptionHandler.fromDoubleFunction(DoubleFunction), in which case its return value is empty when the underlyingDoubleFunctionthrows an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Optional<R>apply(double value)Variation ofDoubleFunction.apply(double)that returnsOptional.default DoubleFunction<R>orElse(R result)Converts thisOptionalDoubleFunctionto plainDoubleFunctionusing default value.default DoubleFunction<R>orElseGet(Supplier<R> source)
-
-
-
Method Detail
-
apply
Optional<R> apply(double value)
Variation ofDoubleFunction.apply(double)that returnsOptional. If thisOptionalDoubleFunctionis obtained fromExceptionHandler.fromDoubleFunction(DoubleFunction), theOptionalwill be empty only if the underlyingDoubleFunctionthrows. Otherwise the returnedOptionaljust wraps the return value of underlyingDoubleFunction(possiblynull).- Specified by:
-
applyin interfaceDoubleFunction<R> - Parameters:
-
value- seeDoubleFunction.apply(double) - Returns:
-
Optionaltypically 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)
Converts thisOptionalDoubleFunctionto plainDoubleFunctionusing default value. The returnedDoubleFunctionwill unwrap present value from theOptionalif possible, or returnresultif theOptionalis empty.- Parameters:
-
result- default value to return instead of an emptyOptional - Returns:
-
plain
DoubleFunctionthat either unwrapsOptionalor returns default value - See Also:
-
orElseGet(Supplier),Optional.orElse(Object)
-
orElseGet
default DoubleFunction<R> orElseGet(Supplier<R> source)
Converts thisOptionalDoubleFunctionto plainDoubleFunctionusing fallbackSupplier. The returnedDoubleFunctionwill unwrap present value from theOptionalif possible, or fall back to callingsourceif theOptionalis empty.- Parameters:
-
source-Supplierto query for fallback value whenOptionalis empty - Returns:
-
plain
DoubleFunctionthat either unwrapsOptionalor falls back tosource - See Also:
-
orElse(Object),Optional.orElseGet(Supplier)
-
-