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