FlatMap v/s CompactMap v/s Map in swift

#Map

  • Map tranform an array of values into an array of another values
  • Map return in form of array of array ( for e.g [[String]])

#FlatMap

  • Map make the things complicated while accessing so we used FlatMap
  • FlatMap is similary to Map but it's flatten a result of nested collections into single collection

#CompactMap

  • Map & Flat Map don't handle the nil error so we used compactMap to handle that