Swift's API includes many functions and instance methods that reflect its functional programming heritage. A Prime example is called reduce. You can reduce a collection of values from just one value, such as calculating the sum of every person's age in an ARRA Y of Person objects. Using Reduce eliminates the need for writing many loops in a program. Here's an annotated code listing, shows a loop and the equivalent usage of reduce to add together the age of Every person in an array.
There is three matching parts between the code snippets. The green box in both snippets shows how a initial value is defined, in this case zero. The yellow underline shows how each approach iterates the array of person objects. The red underline is a where the sum is accumulated. in the reduce code, the first closure argument ($) is the running total, which starts at zero, and the Second parameter ($) References A person object in the people array.