2424import static io .vavr .CheckedConsumerModule .sneakyThrow ;
2525
2626/**
27- * A consumer that may throw, equivalent to {@linkplain java.util.function.Consumer}.
27+ * A {@linkplain java.util.function.Consumer} that is allowed to throw checked exceptions .
2828 *
29- * @param <T> the value type supplied to this consumer.
29+ * @param <T> the type of the input to the consumer
3030 */
3131@ FunctionalInterface
3232public interface CheckedConsumer <T > {
3333
3434 /**
35- * Creates a {@code CheckedConsumer}.
35+ * Creates a {@code CheckedConsumer} from the given method reference or lambda .
3636 *
37+ * <p>Example usage:</p>
3738 * <pre>{@code
3839 * final CheckedConsumer<Value> checkedConsumer = CheckedConsumer.of(Value::stdout);
3940 * final Consumer<Value> consumer = checkedConsumer.unchecked();
4041 *
41- * // prints "Hi" on the console
42+ * // prints "Hi" to the console
4243 * consumer.accept(CharSeq.of("Hi!"));
4344 *
44- * // throws
45+ * // may throw an exception
4546 * consumer.accept(null);
4647 * }</pre>
4748 *
48- * @param methodReference ( typically) a method reference, e.g. {@code Type::method}
49- * @param <T> type of values that are accepted by the consumer
50- * @return a new {@code CheckedConsumer}
49+ * @param methodReference typically a method reference, e.g. {@code Type::method}
50+ * @param <T> the type of values accepted by the consumer
51+ * @return a new {@code CheckedConsumer} wrapping the given method reference
5152 * @see CheckedFunction1#of(CheckedFunction1)
5253 */
5354 static <T > CheckedConsumer <T > of (CheckedConsumer <T > methodReference ) {
5455 return methodReference ;
5556 }
5657
5758 /**
58- * Performs side-effects.
59+ * Performs an action on the given value, potentially causing side-effects.
5960 *
60- * @param t a value of type {@code T}
61- * @throws Throwable if an error occurs
61+ * @param t the input value of type {@code T}
62+ * @throws Throwable if an error occurs during execution
6263 */
6364 void accept (T t ) throws Throwable ;
6465
6566 /**
66- * Returns a chained {@code CheckedConsumer} that first executes {@code this.accept(t)}
67- * and then {@code after .accept(t)}, for a given {@code t} of type {@code T }.
67+ * Returns a composed {@code CheckedConsumer} that performs, in sequence,
68+ * {@code this .accept(t)} followed by {@code after.accept(t)} for the same input {@code t }.
6869 *
69- * @param after the action that will be executed after this action
70+ * @param after the action to execute after this action
7071 * @return a new {@code CheckedConsumer} that chains {@code this} and {@code after}
7172 * @throws NullPointerException if {@code after} is null
7273 */
@@ -76,9 +77,10 @@ default CheckedConsumer<T> andThen(CheckedConsumer<? super T> after) {
7677 }
7778
7879 /**
79- * Returns an unchecked {@link Consumer} that will <em>sneaky throw</em> if an exceptions occurs when accepting a value.
80+ * Returns an unchecked {@link Consumer} that <em>sneakily throws</em> any exception
81+ * encountered while accepting a value.
8082 *
81- * @return a new {@link Consumer} that throws a {@code Throwable}.
83+ * @return a {@link Consumer} that may throw any {@link Throwable} without declaring it
8284 */
8385 default Consumer <T > unchecked () {
8486 return t -> {
0 commit comments