Created
May 5, 2014 17:58
-
-
Save mschuetz/3fb73d73d9d71eaa0e47 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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