Functional Programming - Introduction
In functional programming languages, functions are the main building blocks. There are many requirements about how you define a function and what you can do with it. In return, you’re able to create programs that are easy to understand, debug, test, and expand, with no need to worry about concurrency issues.
Although Swift isn’t a functional programming language, its creators adopted many functional programming features. This lets you use functional programming practices to create code that’s easier to read and test, with less need for explicit thread-safety mechanisms.
Learning Objectives
You’ve already seen the functional programming higher-order functions map, filter, reduce, and sort. You learned how to use them with Swift collections in Programming in Swift: Functions & Types, where you learned the term “functional programming”. In this lesson, you’ll learn more about functional programming principles, and how you can apply them when writing Swift code:
- Immutability and stateless programming
- Pure functions
- Declarative programming style
- Function composition