Created
May 16, 2020 16:51
-
-
Save benweidig/db28981dde2a20f0976a0fd6042ef6be 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
@FunctionalInterface | |
interface ExFunction<T, R, E extends Exception> { | |
R apply(T t) throws E; | |
} | |
<T, R, E extends Exception> Function<T, R> uncheck(ExFunction<T, R, E> fn) { | |
return arg -> { | |
try { | |
return fn.apply(arg); | |
} | |
catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
}; | |
} | |
// Now we can build a stream | |
public void doWork(List<MyBean> beans) { | |
beans.stream() | |
.map(uncheck(bean -> ...)) | |
.forEach(uncheck(item -> ...)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment