Functional Programming
Swift adopts some patterns from the functional programming paradigm. It is difficult to provide a concrete definition of functional programming because people use the phrase with different meanings and intentions, but typically it is understood to include:
-
First-class functions – functions can be passed as arguments to other functions, can be stored in variables, etc.; they are just like any other type.
-
Pure functions – functions have no side effects; functions, given the same input, always return the same output, and do not modify other states elsewhere in the program. Most math functions like sin, cos, fibonacci, and factorial are pure.
-
Immutability – mutability is de-emphasized as it is more difficult ...
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.