The collections included in Swift allow us the use of higher order functions, that is, functions that take other functions and use them to perform transformations on datasets. For example, an array provides us with the
As previously explained, the preceding code represents an imperative version of array filtering. We can achieve the same goal with a functional approach using the
filter method included in all the types that conform to the
Sequence protocol. The
Array<Element> struct conforms to the
Sequence protocol and many other protocols. In Swift versions prior to 3, the
Sequence protocol was named
As it happens in most modern languages, Swift supports ...