Skip to content

Instantly share code, notes, and snippets.

@marschall
Last active October 16, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marschall/f71c67097fc40e040f53 to your computer and use it in GitHub Desktop.
Save marschall/f71c67097fc40e040f53 to your computer and use it in GitHub Desktop.
public class SequenceableCollection {
public static <T> List<T> streamContents(Supplier<List<T>> constructor, Consumer<Consumer<T>> block) {
List<T> result = constructor.get();
block.accept(each -> result.add(each));
return result;
}
public static List<String> example(ResultSet rs) {
return streamContents(ArrayList::new, (accumulator) -> {
try {
while (rs.next()) {
accumulator.accept(rs.getString(1));
}
} catch (SQLException e) {
throw new RuntimeException("can't read result set", e);
}
});
}
}
@adriaon
Copy link

adriaon commented Oct 16, 2015

Why is there an SQLException reference in there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment