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 returned from and 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access