https://kotlinlang.org logo
Title
k

kef

02/05/2018, 7:47 PM
Hi guys. I want do do some basic stuff and I’m stuck. What’s the fastest way to do convert:
val a = listOf(Pair("a", 1), Pair("a", 2), Pair("b", 1))
into:
[(a, 3), (b, 1)]
So, just group by key and sum values Best I can do is:
a.groupBy ({ it.first}, {it.second} ).map{(key, value) -> key to value.sum()}
but there must be better way
r

Ruckus

02/05/2018, 7:48 PM
Please stop cross posting
k

kef

02/05/2018, 7:50 PM
Sorry, won’t do that again.
👍 1
r

Ruckus

02/05/2018, 8:00 PM
I don't mean to sound rude. We've had uses in the past spam every channel they can find and it gets annoying. In this case, pretty much everyone in #getting-started is in #general, so duplicating the post here will just spam the same people again, not increase visibility.
Basically, post something where you think it goes best an wait until you either get an answer or someone reccomends posting in another channel instead.
k

kef

02/05/2018, 8:06 PM
I fully understand. I’ve just removed my post from general. Hopefully someone can help me here. Thanks!