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

com.github.tonivade.purefun.CheckedConsumer2 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 CheckedConsumer2 extends Recoverable {

  void accept(A value1, B value2) throws Exception;

  default Consumer2 unchecked() {
    return (a, b) -> {
      try {
        accept(a, b);
      } catch (Exception e) {
        sneakyThrow(e);
      }
    };
  }

  default CheckedFunction2> peek() {
    return (a, b) -> { accept(a, b); return Tuple.of(a, b); };
  }

  default CheckedConsumer2 andThen(CheckedConsumer2 after) {
    return (value1, value2) -> { accept(value1, value2); after.accept(value1, value2); };
  }

  default CheckedFunction2 asFunction() {
    return (value1, value2) -> { accept(value1, value2); return unit(); };
  }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy