https://kotlinlang.org logo
Title
m

menegatti

08/16/2017, 9:53 AM
data.groupBy { it[0] }.mapValues { (_, value) -> value.map { it[1] } }
👍 2
t

tipsy

08/16/2017, 10:07 AM
thanks, this language (and the slack channel) never disappoints
k

karelpeeters

08/16/2017, 10:48 AM
Why not
data.groupBy { it[0] }.mapValues { (_, value) -> value[1]}
?
a

arekolek

08/16/2017, 10:52 AM
Why not
data.groupBy({ it[0] }, { it[1] })
? 😉
k

karelpeeters

08/16/2017, 10:56 AM
Even better.
t

tipsy

08/16/2017, 10:56 AM
nice
that's perfect @arekolek, thanks
👍 1
i need the value to be an
Array<String>
rather than a
List<String>
though, where do i put that with this approach? 🤔
k

kirillrakhman

08/16/2017, 11:11 AM
put
.toTypedArray()
at the end of the call
a

arekolek

08/16/2017, 11:11 AM
I guess that would be
data.groupBy({ it[0] }, { it[1] }).mapValues { it.value.toList() }
t

tipsy

08/16/2017, 11:14 AM
still more readable i think
return data.groupBy(
    { it[0] },
    { it[1] }
).mapValues { it.value.toTypedArray() }
a

arekolek

08/16/2017, 11:16 AM
I read that wrong, I thought you needed a list, which it already was 😛
t

tipsy

08/16/2017, 11:17 AM
i wish i needed a list 😄
m

menegatti

08/16/2017, 11:43 AM
@arekolek nice one, I didn't know
groupBy
took more than one lambda