Created
November 6, 2017 21:57
-
-
Save pellse/4f8d176b88568de5d0cb31c06e84332a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressWarnings("unchecked") | |
public static <T, E extends Exception> T sneakyThrow(Exception e) throws E { | |
throw (E) e; | |
} | |
public static <T, R> Function<T, R> unchecked(CheckedFunction<T, R> checkedFunction) { | |
return t -> { | |
try { | |
return checkedFunction.apply(t); | |
} catch (Exception e) { | |
return sneakyThrow(e); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment