Thinking Functionally in Swift (One day)
This course is for experienced Swift developers who want to explore Functional Programming. To book this course for your group, company, or public event see Booking and Availability.
At the end of this day, you'll look at functions differently. Actually, you'll look at functions differently from the very start of the day when we express Sets and Pictures using structs that contain nothing more than a single property that is a closure.
Next, we review the map() function for arrays and generalize the concept to map for Optionals, Swift 5's new Result type, and our own tyoe. The goal is for you to see map as a design pattern.
A type that supports map is a Functor and one that supports flatMap is a Monad. In our third section we'll look at two flatMaps that are part of the Swift standard library and a third that has been renamed to compactMap. You'll understand why this renaming was a good idea and you'll come to appreciate where we want to use a flatMap.
Our final section looks at a higher-order function that is somewhere in between map and flatMap: apply. In some ways apply is more powerful than flatMap and we'll see that in some situations we get a lot of return with very little effort.
We assume that you are an experienced programmer who has spent some time looking at Swift but you are relatively new to Functional Programming.
You need a Mac running the latest public version of Xcode. You'll create Swift playgrounds.
Higher Order Functions
Drawing Pictures Demo
Our own map
Swift 5 Result Type
Non-Container Map (Optional)
FlatMapping Result Type
Our own flatMap
FlatMap and Map
Random Number Generators (optional)
Monoids and Applicatives (optional)
You will find much of this content and more in the book A Functional Programming Kickstart available from Editors Cut.