Module com.machinezoo.noexception
Interface OptionalUnaryOperator<T>
-
- Type Parameters:
-
T- seeUnaryOperator
- 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 OptionalUnaryOperator<T> extends Function<T,Optional<T>>
Variation ofUnaryOperatorthat returnsOptionalinstead of the raw value.OptionalUnaryOperatoris typically obtained fromExceptionHandler.fromUnaryOperator(UnaryOperator), in which case its return value is empty when the underlyingUnaryOperatorthrows an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Optional<T>apply(T operand)Variation ofFunction.apply(Object)that returnsOptional.default UnaryOperator<T>orElse(T result)Converts thisOptionalUnaryOperatorto plainUnaryOperatorusing default value.default UnaryOperator<T>orElseGet(Supplier<T> source)
-
-
-
Method Detail
-
apply
Optional<T> apply(T operand)
Variation ofFunction.apply(Object)that returnsOptional. If thisOptionalUnaryOperatoris obtained fromExceptionHandler.fromUnaryOperator(UnaryOperator), theOptionalwill be empty only if the underlyingUnaryOperatorthrows. Otherwise the returnedOptionaljust wraps the return value of underlyingUnaryOperator(possiblynull).- Specified by:
-
applyin interfaceFunction<T,Optional<T>> - Parameters:
-
operand- seeFunction.apply(Object) - Returns:
-
Optionaltypically wrapping return value ofFunction.apply(Object), or an emptyOptional(typically signifying an exception) - See Also:
-
ExceptionHandler.fromUnaryOperator(UnaryOperator),Function.apply(Object)
-
orElse
default UnaryOperator<T> orElse(T result)
Converts thisOptionalUnaryOperatorto plainUnaryOperatorusing default value. The returnedUnaryOperatorwill unwrap present value from theOptionalif possible, or returnresultif theOptionalis empty.- Parameters:
-
result- default value to return instead of an emptyOptional - Returns:
-
plain
UnaryOperatorthat either unwrapsOptionalor returns default value - See Also:
-
orElseGet(Supplier),Optional.orElse(Object)
-
orElseGet
default UnaryOperator<T> orElseGet(Supplier<T> source)
Converts thisOptionalUnaryOperatorto plainUnaryOperatorusing fallbackSupplier. The returnedUnaryOperatorwill unwrap present value from theOptionalif possible, or fall back to callingsourceif theOptionalis empty.- Parameters:
-
source-Supplierto query for fallback value whenOptionalis empty - Returns:
-
plain
UnaryOperatorthat either unwrapsOptionalor falls back tosource - See Also:
-
orElse(Object),Optional.orElseGet(Supplier)
-
-