NEW: Get your ticket to Hacking with Swift Live! >>

How to improve your functional programming skills?

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.

Listen on Apple Podcasts

Hacking with Swift is sponsored by Essential Developer

SPONSORED From August 2nd to 8th you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!

Save your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

BUY OUR BOOKS
Buy Pro Swift Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift (Vapor Edition) Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Server-Side Swift (Kitura Edition) Buy Beyond Code

Was this page useful? Let us know!

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.