All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tonivade.purefun.CheckedConsumer1 Maven / Gradle / Ivy

/*
 * Copyright (c) 2018-2019, Antonio Gabriel Muñoz Conejo 
 * Distributed under the terms of the MIT License
 */
package com.github.tonivade.purefun;

import static com.github.tonivade.purefun.Unit.unit;

@FunctionalInterface
public interface CheckedConsumer1 extends Recoverable {

  void accept(A value) throws Throwable;

  default CheckedFunction1 asFunction() {
    return value -> { accept(value); return unit(); };
  }

  default CheckedConsumer1 andThen(CheckedConsumer1 after) {
    return value -> { accept(value); after.accept(value); };
  }

  default Consumer1 unchecked() {
    return value -> {
      try {
        accept(value);
      } catch (Throwable e) {
        sneakyThrow(e);
      }
    };
  }

  default CheckedFunction1 peek() {
    return value -> { accept(value); return value; };
  }

  static  CheckedConsumer1 of(CheckedConsumer1 reference) {
    return reference;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy