How to use the Array’s three closure functions: map(), filter(), and reduce()

How to declare and use closures in your functions

One of the important features in Swift is the closure. Closures are self-contained blocks of code that can be passed to functions to be executed as independent code units. Think of a closure as a function without a name. In fact, functions are actually special cases of closures.

Swift offers various ways to optimize closures so that they are brief and succinct. The various optimizations include the following: