Not sure if I'm missing something here but I have ...
# getting-started
c
Not sure if I'm missing something here but I have
data class Person(val phoneNumbers: List<String>, val metaData: String)
and then a list of people ( ie
val people: List<Person>
) and I wanna map it into a single list of phone numbers. That's easy right?
people.flatMap{ it.phoneNumbers }
cool. that makes sense. but now I actually want to flat map it into a list of phone numbers, and with each phone number I want to attach a piece of metaData so the final type is List<PairString, String. Any ideas?
r
something like:
people.flatMap { person -> person.phoneNumbers.map { it to person.metaData } }
?
or
person.metaData to it
, depending on which side of the Pair the phonenumber should be
c
Phone number should be on the left, and meta data on the right. Hm. Could it be as simple as a map inside of the flatmap!? let me try 🙏
yeah, i think that just about does it. thank you so much @Riccardo Lippolis i wouldn't have thought of that. i was just looking for a different operator in general. lol
👍 1
j
Do you have repeated phones? If not, probably you should go with a Map and use any group API
c
id have to check actually, but thanks for the idea Javier