Module com.machinezoo.noexception
Interface OptionalLongFunction<R>
-
- Type Parameters:
-
R- seeLongFunction
- All Superinterfaces:
-
LongFunction<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 OptionalLongFunction<R> extends LongFunction<Optional<R>>
Variation ofLongFunctionthat returnsOptionalinstead of the raw value.OptionalLongFunctionis typically obtained fromExceptionHandler.fromLongFunction(LongFunction), in which case its return value is empty when the underlyingLongFunctionthrows an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Optional<R>apply(long value)Variation ofLongFunction.apply(long)that returnsOptional.default LongFunction<R>orElse(R result)Converts thisOptionalLongFunctionto plainLongFunctionusing default value.default LongFunction<R>orElseGet(Supplier<R> source)
-
-
-
Method Detail
-
apply
Optional<R> apply(long value)
Variation ofLongFunction.apply(long)that returnsOptional. If thisOptionalLongFunctionis obtained fromExceptionHandler.fromLongFunction(LongFunction), theOptionalwill be empty only if the underlyingLongFunctionthrows. Otherwise the returnedOptionaljust wraps the return value of underlyingLongFunction(possiblynull).- Specified by:
-
applyin interfaceLongFunction<R> - Parameters:
-
value- seeLongFunction.apply(long) - Returns:
-
Optionaltypically wrapping return value ofLongFunction.apply(long), or an emptyOptional(typically signifying an exception) - See Also:
-
ExceptionHandler.fromLongFunction(LongFunction),LongFunction.apply(long)
-
orElse
default LongFunction<R> orElse(R result)
Converts thisOptionalLongFunctionto plainLongFunctionusing default value. The returnedLongFunctionwill unwrap present value from theOptionalif possible, or returnresultif theOptionalis empty.- Parameters:
-
result- default value to return instead of an emptyOptional - Returns:
-
plain
LongFunctionthat either unwrapsOptionalor returns default value - See Also:
-
orElseGet(Supplier),Optional.orElse(Object)
-
orElseGet
default LongFunction<R> orElseGet(Supplier<R> source)
Converts thisOptionalLongFunctionto plainLongFunctionusing fallbackSupplier. The returnedLongFunctionwill unwrap present value from theOptionalif possible, or fall back to callingsourceif theOptionalis empty.- Parameters:
-
source-Supplierto query for fallback value whenOptionalis empty - Returns:
-
plain
LongFunctionthat either unwrapsOptionalor falls back tosource - See Also:
-
orElse(Object),Optional.orElseGet(Supplier)
-
-