Functional Swift

The really cool new stuff in Swift is all functional programming features. There are two main facets to Swift’s version of functional programming: managing mutability, and first-class functions and closures.

Managing Mutability

In programming, you can’t avoid mutable state. It’s a fact. Most of the time, it’s the reason that we’re using a computer. For example, say I’m using a program called Atom to write a blog post. There wouldn’t be any point in using Atom if I couldn’t modify the file I’m writing.

But mutable state makes things complicated. In a large, complex software system, code that avoids mutating things is usually easier to understand, less prone to errors and unexpected side effects, and easier to interact with. ...

Get Functional Programming: A PragPub Anthology now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.