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

com.github.tonivade.purefun.CheckedRunnable 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;

@FunctionalInterface
public interface CheckedRunnable extends Recoverable {

  void run() throws Throwable;

  default CheckedProducer asProducer() {
    return () -> { run(); return Unit.unit(); };
  }

  default Runnable recover(Consumer1 mapper) {
    return () -> {
      try {
        run();
      } catch(Throwable e) {
        mapper.accept(e);
      }
    };
  }

  default Runnable unchecked() {
    return recover(this::sneakyThrow);
  }

  static  CheckedRunnable failure(Producer supplier) {
    return () -> { throw supplier.get(); };
  }

  static CheckedRunnable of(CheckedRunnable runnable) {
    return runnable;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy