Package io.vavr
Interface CheckedConsumer<T>
- Type Parameters:
T
- the value type supplied to this consumer.
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A consumer that may throw, equivalent to Consumer.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Performs side-effects.default CheckedConsumer
<T> andThen
(CheckedConsumer<? super T> after) Returns a chainedCheckedConsumer
that first executesthis.accept(t)
and thenafter.accept(t)
, for a givent
of typeT
.static <T> CheckedConsumer
<T> of
(CheckedConsumer<T> methodReference) Creates aCheckedConsumer
.Returns an uncheckedConsumer
that will sneaky throw if an exceptions occurs when accepting a value.
-
Method Details
-
of
Creates aCheckedConsumer
.final CheckedConsumer<Value> checkedConsumer = CheckedConsumer.of(Value::stdout); final Consumer<Value> consumer = checkedConsumer.unchecked(); // prints "Hi" on the console consumer.accept(CharSeq.of("Hi!")); // throws consumer.accept(null);
- Type Parameters:
T
- type of values that are accepted by the consumer- Parameters:
methodReference
- (typically) a method reference, e.g.Type::method
- Returns:
- a new
CheckedConsumer
- See Also:
-
accept
Performs side-effects.- Parameters:
t
- a value of typeT
- Throws:
Throwable
- if an error occurs
-
andThen
Returns a chainedCheckedConsumer
that first executesthis.accept(t)
and thenafter.accept(t)
, for a givent
of typeT
.- Parameters:
after
- the action that will be executed after this action- Returns:
- a new
CheckedConsumer
that chainsthis
andafter
- Throws:
NullPointerException
- ifafter
is null
-
unchecked
Returns an uncheckedConsumer
that will sneaky throw if an exceptions occurs when accepting a value.- Returns:
- a new
Consumer
that throws aThrowable
.
-