Skip to content

Commit

Permalink
refactor: make TryConsumer public
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Aug 28, 2024
1 parent bc7cfaf commit 3f92e4c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core-jdk8/src/main/java/org/bsc/langgraph4j/utils/TryConsumer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.bsc.langgraph4j.utils;

import java.util.function.Consumer;

@FunctionalInterface
public interface TryConsumer<T, Ex extends Throwable> extends Consumer<T> {

void tryAccept( T t ) throws Ex;

default void accept( T t ) {
try {
tryAccept(t);
} catch (Throwable ex) {
throw new RuntimeException(ex);
}
}

static <T,Ex extends Throwable> Consumer<T> Try( TryConsumer<T, Ex> consumer ) {
return consumer;
}
}

0 comments on commit 3f92e4c

Please sign in to comment.