T
- see BinaryOperator
@FunctionalInterface public interface OptionalBinaryOperator<T> extends BiFunction<T,T,Optional<T>>
BinaryOperator
that returns Optional
instead of the raw value. OptionalBinaryOperator
is typically obtained from ExceptionHandler.fromBinaryOperator(BinaryOperator)
, in which case its return value is empty when the underlying BinaryOperator
throws an exception. See noexception tutorial.
Modifier and Type | Method and Description |
---|---|
Optional<T> |
apply(T left, T right)
Variation of BiFunction.apply(Object, Object) that returns Optional .
|
default BinaryOperator<T> |
orElse(T result)
Converts this OptionalBinaryOperator to plain BinaryOperator using default value.
|
default BinaryOperator<T> |
orElseGet(Supplier<T> source)
|
andThen
Optional<T> apply(T left, T right)
BiFunction.apply(Object, Object)
that returns Optional
. If this OptionalBinaryOperator
is obtained from ExceptionHandler.fromBinaryOperator(BinaryOperator)
, the Optional
will be empty only if the underlying BinaryOperator
throws. Otherwise the returned Optional
just wraps the return value of underlying BinaryOperator
(possibly null
).
apply
in interface BiFunction<T,T,Optional<T>>
left
- see BiFunction.apply(Object, Object)
right
- see BiFunction.apply(Object, Object)
Optional
typically wrapping return value of BiFunction.apply(Object, Object)
, or an empty Optional
(typically signifying an exception)
ExceptionHandler.fromBinaryOperator(BinaryOperator)
, BiFunction.apply(Object, Object)
default BinaryOperator<T> orElse(T result)
OptionalBinaryOperator
to plain BinaryOperator
using default value. The returned BinaryOperator
will unwrap present value from the Optional
if possible, or return result
if the Optional
is empty.
result
- default value to return instead of an empty Optional
BinaryOperator
that either unwraps Optional
or returns default value
orElseGet(Supplier)
, Optional.orElse(Object)
default BinaryOperator<T> orElseGet(Supplier<T> source)
OptionalBinaryOperator
to plain BinaryOperator
using fallback Supplier
. The returned BinaryOperator
will unwrap present value from the Optional
if possible, or fall back to calling source
if the Optional
is empty.
source
- Supplier
to query for fallback value when Optional
is empty
BinaryOperator
that either unwraps Optional
or falls back to source
orElse(Object)
, Optional.orElseGet(Supplier)
Copyright © 2017–2020 Robert Važan. All rights reserved.