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 chained CheckedConsumer that first executes this.accept(t) and then after.accept(t), for a given t of type T.
      static <T> CheckedConsumer<T> of​(CheckedConsumer<T> methodReference)
      Creates a CheckedConsumer.
      default java.util.function.Consumer<T> unchecked()
      Returns an unchecked Consumer that will sneaky throw if an exceptions occurs when accepting a value.
    • Method Detail

      • of

        static <T> CheckedConsumer<T> of​(CheckedConsumer<T> methodReference)
        Creates a CheckedConsumer.
        
         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 type T
        Throws:
        java.lang.Throwable - if an error occurs
      • andThen

        default CheckedConsumer<T> andThen​(CheckedConsumer<? super T> after)
        Returns a chained CheckedConsumer that first executes this.accept(t) and then after.accept(t), for a given t of type T.
        Parameters:
        after - the action that will be executed after this action
        Returns:
        a new CheckedConsumer that chains this and after
        Throws:
        java.lang.NullPointerException - if after is null
      • unchecked

        default java.util.function.Consumer<T> unchecked()
        Returns an unchecked Consumer that will sneaky throw if an exceptions occurs when accepting a value.
        Returns:
        a new Consumer that throws a Throwable.