Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@OndraZizka
Created July 8, 2020 11:49
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 OndraZizka/a3c846cf1b1e80072f5442be816b43ce to your computer and use it in GitHub Desktop.
Save OndraZizka/a3c846cf1b1e80072f5442be816b43ce to your computer and use it in GitHub Desktop.
Parser - Map from comma separated pairs, in Kotlin
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