Skip to content

Instantly share code, notes, and snippets.

@saswata-dutta
Created July 13, 2023 06:52
Show Gist options
  • Save saswata-dutta/e9a82c0ddb10f7ee9fc974f6690ad18f to your computer and use it in GitHub Desktop.
Save saswata-dutta/e9a82c0ddb10f7ee9fc974f6690ad18f to your computer and use it in GitHub Desktop.

Revisions

  1. saswata-dutta created this gist Jul 13, 2023.
    17 changes: 17 additions & 0 deletions ThrowingConsumer.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    @FunctionalInterface
    interface ThrowingConsumer<T, E extends Exception> {
    void accept(T t) throws E;

    static <T> Consumer<T> unchecked(ThrowingConsumer<T, Exception> t) {

    return arg -> {
    try {
    t.accept(arg);
    } catch (Exception ex) {
    throw new RuntimeException(ex);
    }
    };
    }
    }

    // threads.forEach(ThrowingConsumer.unchecked(Thread::join));