Created
July 8, 2020 11:49
-
-
Save OndraZizka/a3c846cf1b1e80072f5442be816b43ce to your computer and use it in GitHub Desktop.
Parser - Map from comma separated pairs, in Kotlin
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
fun parseCommaDelimitedMap(str: String): Map<String, String> { | |
if (str == null) return null | |
val pairs = str.split(',').map { it.trim() }.filter { it.contains(':') } | |
.map { | |
val parts = it.split(':', limit = 2) | |
Pair(parts[0], parts[1]) | |
} | |
.associate { it } | |
return pairs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment