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.
@FunctionalInterface public interface CheckedConsumer<T>
A consumer that may throw, equivalent to Consumer.
-
-
Method Summary
Modifier and Type Method Description void
accept(T t)
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
.default java.util.function.Consumer<T>
unchecked()
Returns an uncheckedConsumer
that will sneaky throw if an exceptions occurs when accepting a value.
-
-
-
Method Detail
-
of
static <T> CheckedConsumer<T> of(CheckedConsumer<T> methodReference)
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:
CheckedFunction1.of(CheckedFunction1)
-
accept
void accept(T t) throws java.lang.Throwable
Performs side-effects.- Parameters:
t
- a value of typeT
- Throws:
java.lang.Throwable
- if an error occurs
-
andThen
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
.- Parameters:
after
- the action that will be executed after this action- Returns:
- a new
CheckedConsumer
that chainsthis
andafter
- Throws:
java.lang.NullPointerException
- ifafter
is null
-
unchecked
default java.util.function.Consumer<T> unchecked()
Returns an uncheckedConsumer
that will sneaky throw if an exceptions occurs when accepting a value.- Returns:
- a new
Consumer
that throws aThrowable
.
-
-