Want to know when I need to use flatMap

Hi @scotteg

just want to know when I should use flatMap and can I use flat map without having return type observable

flatMap {

I need some reason to implement it. Please help me .



@lohanrakesh. Thanks very much for your question! With respect to using flatMap:

When you need to transform the contents of an array of arrays, into a linear array use flatMap:


let users: [User] = ā€¦
let allEmails = users.flatMap { $0.emails }

In the above example, Iā€™m not using a return type observable, so this should be a good example.

I hope this helps!

All the best!

This topic was automatically closed after 166 days. New replies are no longer allowed.