Last active
August 18, 2018 08:45
-
-
Save pauldambra/a96bd0839464a596dfc373fc85adbbde to your computer and use it in GitHub Desktop.
Beautiful
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
private static final Splitter newlineSplitter = Splitter.on(Pattern.compile("\r?\n")); | |
private static final Splitter spaceSplitter = Splitter.on(CharMatcher.whitespace()).omitEmptyStrings(); | |
Map<String, String> substitutions = newlineSplitter | |
.splitToList(text) | |
.stream() | |
.map(spaceSplitter::splitToList) | |
.filter(r -> r.size() != 0) | |
.collect(Collectors.toMap( | |
ss -> ss.get(0), | |
ss -> ss.get(1) | |
)); |
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
val substitutions = text.split(Pattern.compile("\r?\n")) | |
.map { it.split(' ') } | |
.filter { it.isNotEmpty() } | |
.associate { it[0] to it[1] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Takes input
and converts to a map