Is there any quick way to "reverse" map, so make a...
# announcements
m
Is there any quick way to "reverse" map, so make a
Map<A, B>
into
Map<B, List<A>>
?
Even better,
Map<A, List<B>>
into
Map<B, List<A>>
e
Copy code
fun <A, B> Map<A, List<B>>.reverse(): Map<B, List<A>> = flatMap { it.value.map { v -> it.key to v } }
                    .groupBy({ it.second }, { it.first })
­čĹŹ 2
100 Views