Recorded – watch the full episode on YouTube.
How could folks who have some experience already with functional programming take their skills to the next level? What does that look like in terms of a roadmap?
Daniel Steinberg: There's a couple things there. One is, if you understand why
compactMap() was renamed to
compactMap(), or at least why it was renamed away from
flatMap(), that's a great step because it means you understand the shape of these things. And so understanding the shape of these things, for instance,
zip(): you can take
zip() and pass it two arrays, so basically you're passing
zip() a tuple of arrays, and you're getting back an array of tuples.
“If you understand the shape of things, you've made a big step. Now I'm not saying you have to go take a class in category theory.”
If you understand the shape of things, you've made a big step. Now I'm not saying you have to go take a class in category theory. Without words like functor and monad, but just seeing the shape of what you're doing and you say, “oh, map is useful for arrays. It's useful for the
Result type. There's something in Combine for it. There's something in optionals for it. I have a type that is generic in something, I bet there's a good map for that as well." And now you start writing map for your own types.
Paul Hudson: It's interesting that the use of map has grown because it was just in optional sequences, but now of course
Result has map as well, and we can use it there. You say that the shape of the function starts to matter more. When you see
flatMap(), you know what that means hopefully, if they've been used correctly. You know what that means and the implications it has for your code, no matter what type it's being called on.
Daniel Steinberg: That's right. And so once you understand that, what I say is, that's the step of where you go from seeing map as a function in the Swift standard library to seeing map as a design pattern. And now we start to see functional design patterns the same way we saw strategy and these OO design patterns that we saw from the Gang of Four.
This transcript was recorded as part of Swiftly Speaking. You can watch the full original episode on YouTube, or subscribe to the audio version on Apple Podcasts.
SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!
Link copied to your pasteboard.