For the More Curious: Function Currying

After working through this chapter, you might be wondering about the mutating keyword. Why is it needed to allow you to modify a struct or enum? The concept of function currying helps to explain the answer.

Create a new playground called Curry.playground.

Function currying allows you to rewrite an existing function that takes multiple parameters as a new function that takes one parameter and returns another function. The function you return takes the original function’s remaining parameters and returns what the original function returns. This process of nesting functions, each with the remaining number of parameters, continues until there are no remaining parameters.

The rewritten function ...

Get Swift Programming: The Big Nerd Ranch Guide 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.