Last active
October 16, 2015 19:39
-
-
Save marschall/f71c67097fc40e040f53 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
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); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why is there an SQLException reference in there?