diesieben07
08/01/2017, 3:08 PMval list = listOf("hello" to "world", "hello" to "world2", "bla" to "quz")
val result = list.groupingBy { it.first }.fold(null as String?) { acc, elem -> acc ?: elem.second }
val list = listOf("hello" to "world", "hello" to "two worlds", "bla" to "quz")
val result = list.groupingBy { it.first }.aggregate { _, acc: String?, elem, _ -> acc ?: elem.second }
iex
08/01/2017, 3:17 PMmap
- similar to what you did with aggregate
groupBySingle
or similar to do it in one stepdiesieben07
08/01/2017, 3:18 PMgroupingBy
is that it does not construct and intermediary Map<K, List<V>>
for the grouping.iex
08/01/2017, 3:18 PMdiesieben07
08/01/2017, 3:19 PMgroupingBy
like I showed in your extension function 😉iex
08/01/2017, 3:24 PM