Skip to content

Instantly share code, notes, and snippets.

@mschuetz
Created May 5, 2014 17:58
Show Gist options
  • Save mschuetz/3fb73d73d9d71eaa0e47 to your computer and use it in GitHub Desktop.
Save mschuetz/3fb73d73d9d71eaa0e47 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.function.Consumer;
import com.google.common.collect.ImmutableList;
public class Foo {
static interface IOExceptionConsumer<T> {
void accept(T t) throws IOException;
}
static <T> Consumer<T> consumer(IOExceptionConsumer<T> c) {
return (T t) -> {
try {
c.accept(t);
} catch (final IOException e) {
throw new UncheckedIOException(e);
}
};
}
public static void main(String[] args) {
ImmutableList.of(1, 2, 3).stream().forEach(consumer(e -> {
System.out.println(e);
}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment