Package io.vavr
Interface CheckedConsumer<T>
-
- Type Parameters:
T- the type of the input to the 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 is allowed to throw checked exceptions.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaccept(T t)Performs an action on the given value, potentially causing side-effects.default CheckedConsumer<T>andThen(@NonNull CheckedConsumer<? super T> after)Returns a composedCheckedConsumerthat performs, in sequence,this.accept(t)followed byafter.accept(t)for the same inputt.static <T> CheckedConsumer<T>of(@NonNull CheckedConsumer<T> methodReference)Creates aCheckedConsumerfrom the given method reference or lambda.default java.util.function.Consumer<T>unchecked()Returns an uncheckedConsumerthat sneakily throws any exception encountered while accepting a value.
-
-
-
Method Detail
-
of
static <T> CheckedConsumer<T> of(@NonNull CheckedConsumer<T> methodReference)
Creates aCheckedConsumerfrom the given method reference or lambda.Example usage:
final CheckedConsumer<Value> checkedConsumer = CheckedConsumer.of(Value::stdout); final Consumer<Value> consumer = checkedConsumer.unchecked(); // prints "Hi" to the console consumer.accept(CharSeq.of("Hi!")); // may throw an exception consumer.accept(null);- Type Parameters:
T- the type of values accepted by the consumer- Parameters:
methodReference- typically a method reference, e.g.Type::method- Returns:
- a new
CheckedConsumerwrapping the given method reference - See Also:
CheckedFunction1.of(CheckedFunction1)
-
accept
void accept(T t) throws java.lang.Throwable
Performs an action on the given value, potentially causing side-effects.- Parameters:
t- the input value of typeT- Throws:
java.lang.Throwable- if an error occurs during execution
-
andThen
default CheckedConsumer<T> andThen(@NonNull CheckedConsumer<? super T> after)
Returns a composedCheckedConsumerthat performs, in sequence,this.accept(t)followed byafter.accept(t)for the same inputt.- Parameters:
after- the action to execute after this action- Returns:
- a new
CheckedConsumerthat chainsthisandafter - Throws:
java.lang.NullPointerException- ifafteris null
-
unchecked
default java.util.function.Consumer<T> unchecked()
Returns an uncheckedConsumerthat sneakily throws any exception encountered while accepting a value.- Returns:
- a
Consumerthat may throw anyThrowablewithout declaring it
-
-