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
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaccept(T t)Performs side-effects.default CheckedConsumer<T>andThen(CheckedConsumer<? super T> after)Returns a chainedCheckedConsumerthat first executesthis.accept(t)and thenafter.accept(t), for a giventof typeT.static <T> CheckedConsumer<T>of(CheckedConsumer<T> methodReference)Creates aCheckedConsumer.default java.util.function.Consumer<T>unchecked()Returns an uncheckedConsumerthat 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 chainedCheckedConsumerthat first executesthis.accept(t)and thenafter.accept(t), for a giventof typeT.- Parameters:
after- the action that will be executed 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 will sneaky throw if an exceptions occurs when accepting a value.- Returns:
- a new
Consumerthat throws aThrowable.
-
-