Map vs. FlatMap vs. CompactMap

Comparing these functions and when to use which

Sergii Spivakov
Nov 1 · 3 min read

Map

So, let’s imagine that you need to map an array of integers into an array of strings. You can create your own straightforward solution:

You've completed your member preview for this month, but when you sign up for a free Medium account, you get one more story.
Already have an account? Sign in

Sergii Spivakov

Written by

iOS Engineer at Careem | Berlin, 🇩🇪 | https://www.linkedin.com/in/sergii-spivakov-42b99110b/

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade