https://kotlinlang.org logo
Title
f

frellan

07/31/2018, 8:12 PM
I have a map containing keys that map to a list of stuff. I want to iterate all keys of that map and use all entries for each key (a list of stuff) to yield an object that I then collect into a big list of objects. How to I do that? Its
Map<Int, List<Stuff>> -> List<NewStuff>
where new stuff is yielded from each list of stuff
a

Andreas Sinz

07/31/2018, 8:19 PM
map.entries.map { /*convert it.value into List<NewStuff> */ }.flatMap { it }
f

frellan

07/31/2018, 8:28 PM
Is an
entry
every key for a map? In that case can’t you just do
map.flatMap { /*convert it into NewStuff */  }
a

Andreas Sinz

07/31/2018, 9:20 PM
yes,
Map
actual has a
.flatMap
that does what you want