Module com.machinezoo.noexception
Interface OptionalBinaryOperator<T>
-
- Type Parameters:
-
T
- seeBinaryOperator
- All Superinterfaces:
-
BiFunction<T,T,Optional<T>>
- 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 OptionalBinaryOperator<T> extends BiFunction<T,T,Optional<T>>
Variation ofBinaryOperator
that returnsOptional
instead of the raw value.OptionalBinaryOperator
is typically obtained fromExceptionHandler.fromBinaryOperator(BinaryOperator)
, in which case its return value is empty when the underlyingBinaryOperator
throws an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Optional<T>
apply(T left, T right)
Variation ofBiFunction.apply(Object, Object)
that returnsOptional
.default BinaryOperator<T>
orElse(T result)
Converts thisOptionalBinaryOperator
to plainBinaryOperator
using default value.default BinaryOperator<T>
orElseGet(Supplier<T> source)
-
Methods inherited from interface java.util.function.BiFunction
andThen
-
-
-
-
Method Detail
-
apply
Optional<T> apply(T left, T right)
Variation ofBiFunction.apply(Object, Object)
that returnsOptional
. If thisOptionalBinaryOperator
is obtained fromExceptionHandler.fromBinaryOperator(BinaryOperator)
, theOptional
will be empty only if the underlyingBinaryOperator
throws. Otherwise the returnedOptional
just wraps the return value of underlyingBinaryOperator
(possiblynull
).- Specified by:
-
apply
in interfaceBiFunction<T,T,Optional<T>>
- Parameters:
-
left
- seeBiFunction.apply(Object, Object)
-
right
- seeBiFunction.apply(Object, Object)
- Returns:
-
Optional
typically wrapping return value ofBiFunction.apply(Object, Object)
, or an emptyOptional
(typically signifying an exception) - See Also:
-
ExceptionHandler.fromBinaryOperator(BinaryOperator)
,BiFunction.apply(Object, Object)
-
orElse
default BinaryOperator<T> orElse(T result)
Converts thisOptionalBinaryOperator
to plainBinaryOperator
using default value. The returnedBinaryOperator
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
BinaryOperator
that either unwrapsOptional
or returns default value - See Also:
-
orElseGet(Supplier)
,Optional.orElse(Object)
-
orElseGet
default BinaryOperator<T> orElseGet(Supplier<T> source)
Converts thisOptionalBinaryOperator
to plainBinaryOperator
using fallbackSupplier
. The returnedBinaryOperator
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
BinaryOperator
that either unwrapsOptional
or falls back tosource
- See Also:
-
orElse(Object)
,Optional.orElseGet(Supplier)
-
-