In this example it would return a List of a List of authors because we are mapping the Authors from each Book. Using flat map will flatten that into a single list.
The "flatMapTo" function works well if you created a list ahead of time and want to flat map some items to that list. I've been working with Kotlin since late 2016 and honestly can't think of a time I needed to use the "flatMapTo" function, but I'm sure there are some niche scenarios where it'd make sense to use it.
Very good explanation..keep it up
.map{} returns List right ? How does it becomes List
In this example it would return a List of a List of authors because we are mapping the Authors from each Book. Using flat map will flatten that into a single list.
Best explanation, thank you
Sure thing you are very welcome 😊
Is there another function "flatMapTo", what is the purpose of it?
The "flatMapTo" function works well if you created a list ahead of time and want to flat map some items to that list. I've been working with Kotlin since late 2016 and honestly can't think of a time I needed to use the "flatMapTo" function, but I'm sure there are some niche scenarios where it'd make sense to use it.