During this one day advanced Swift workshop we will explore when, where, how, and why to apply aspects of functional programming to your Swift code.
We'll begin the day with a look at functions that consume other functions and move on to situations where you might use functions where you would traditionally reach for a class, then take a moment to discuss some of the key ideas of category theory that are useful to you as a programmer. We'll finish the day by looking at three key patterns that you have encountered in the Swift Standard library and can now incorporate into your code: map, flatMap, and apply.
No one is asking you to stop using Objected Oriented Programming, Protocals, or any other techniques you know and love. The purpose of this workshop is to introduce you to the key aspects of Functional Programming to add powerful tools to your Swift programming toolbox.
Learn how to:
- Use functions where you might traditionally reach for a class
- Incorporate map, flatMap and apply into your code
- Understand key aspects of Functional Programming and add powerful tools to your toolbox
- Create higher-order functions using examples that are familiar to iOS developers
- Find the balance between map() and flatMap() and how to define them in the case of sequences and optionals
Prologue: The Day Ahead
- We have quite a day planned. In this brief introduction, we set the stage for what you'll be learning and how it will fit together.
Part One: Higher Order Functions
- You know that you can store functions in variables and pass them around like you would Strings, Ints, or Arrays. There are also functions that accept these functions as input or that return other functions as output. We begin the day by using and creating these higher-order functions using examples that are familiar to iOS developers.
Part Two: First Class Functions
- We think of functions as specifying behavior but they can often provide everything you might want from a class or a struct. Capture their type with a type alias and you might forget that you're working with functions. We'll look at concrete examples of how you might do this.
Interlude: (Very) Basic Category Theory
- It's become very popular to include concepts and phrases from Category Theory in talks on functional programming. We'll take a few minutes out of our day to look at some of the most important concepts so that we can refer back to them in the next two sections.
Part Three: Map and Functors
- Everyone knows the map() function that defined for Arrays and other Sequence types. We'll look at what is common between it and the map() for Optionals and then create a few map() functions of our own to see that it's essentially a design pattern.
Part Four: FlatMap and Monads
- Swift also defines flatMap() for sequences and optionals. We'll look at the difference between map() and flatMap() and see what is the same in the declaration for sequences and optionals and then create some flatMaps() of our own.
Part Five: Applicatives and Monoids
- Sometimes a map() function isn't enough and a flatMap() is too much. We'll find the balance with applicatives and look at how we might define them in the case of sequences and optionals. We'll look at the requirements and benefits of using this type of function.
Epilogue: A Look Back
- Whether you're heading for home or to the pub, you'll need a moment to collect yourself and arrange everything you learned today. We'll pull everything together and see how the pieces fit and answer any last-minute questions.
This course is for anyone who is already coding in Swift, and would like to learn how and when to apply functional programming to their Swift toolbox.
You should be an experienced developer who is familiar with Swift syntax.
Bring your own hardware
To take part in this workshop you are required to bring a Mac running the latest version of Xcode.