R
- see IntFunction
@FunctionalInterface public interface OptionalIntFunction<R> extends IntFunction<Optional<R>>
IntFunction
that returns Optional
instead of the raw value. OptionalIntFunction
is typically obtained from ExceptionHandler.fromIntFunction(IntFunction)
, in which case its return value is empty when the underlying IntFunction
throws an exception. See noexception tutorial.
Modifier and Type | Method and Description |
---|---|
Optional<R> |
apply(int value)
Variation of IntFunction.apply(int) that returns Optional .
|
default IntFunction<R> |
orElse(R result)
Converts this OptionalIntFunction to plain IntFunction using default value.
|
default IntFunction<R> |
orElseGet(Supplier<R> source)
|
Optional<R> apply(int value)
IntFunction.apply(int)
that returns Optional
. If this OptionalIntFunction
is obtained from ExceptionHandler.fromIntFunction(IntFunction)
, the Optional
will be empty only if the underlying IntFunction
throws. Otherwise the returned Optional
just wraps the return value of underlying IntFunction
(possibly null
).
apply
in interface IntFunction<Optional<R>>
value
- see IntFunction.apply(int)
Optional
typically wrapping return value of IntFunction.apply(int)
, or an empty Optional
(typically signifying an exception)
ExceptionHandler.fromIntFunction(IntFunction)
, IntFunction.apply(int)
default IntFunction<R> orElse(R result)
OptionalIntFunction
to plain IntFunction
using default value. The returned IntFunction
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
IntFunction
that either unwraps Optional
or returns default value
orElseGet(Supplier)
, Optional.orElse(Object)
default IntFunction<R> orElseGet(Supplier<R> source)
OptionalIntFunction
to plain IntFunction
using fallback Supplier
. The returned IntFunction
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
IntFunction
that either unwraps Optional
or falls back to source
orElse(Object)
, Optional.orElseGet(Supplier)
Copyright © 2017–2020 Robert Važan. All rights reserved.