Hi guys. I want do do some basic stuff and I’m stu...
# getting-started
k
Hi guys. I want do do some basic stuff and I’m stuck. What’s the fastest way to do convert:
Copy code
val a = listOf(Pair("a", 1), Pair("a", 2), Pair("b", 1))
into:
Copy code
[(a, 3), (b, 1)]
So, just group by key and sum values Best I can do is:
Copy code
a.groupBy ({ it.first}, {it.second} ).map{(key, value) -> key to value.sum()}
but there must be better way
r
Please stop cross posting
k
Sorry, won’t do that again.
👍 1
r
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
I fully understand. I’ve just removed my post from general. Hopefully someone can help me here. Thanks!