nkiesel
01/03/2023, 5:06 AM{a=[1, 3, 4, 5], b=[1, 3, 4, 5]}
instead of the expected {a=[1, 3, 5], b=[4]}
. Looks the 2nd variant re-uses the initial value for all groups. What is a good use case for the 2nd variant?
val g = listOf("a" to listOf(1, 3), "b" to listOf(4), "a" to listOf(5)).groupingBy { it.first }
g.fold({ _, _ -> mutableListOf<Int>() }, { _, acc, item -> acc.addAll(item.second); acc })
g.fold(mutableListOf<Int>(), { acc, item -> acc.addAll(item.second); acc })
Riccardo Lippolis
01/03/2023, 7:42 AM