The zip function

The zip function is provided by the Swift standard library and creates a sequence of pairs built out of two underlying sequences, where the elements of the ith pair are the ith elements of each underlying sequence.

For instance, in the following example, zip takes two arrays and creates a pair of these two arrays:

let numbers = [3, 5, 9, 10] 
let alphabeticNumbers = ["Three", "Five", "Nine", "Ten"]

let zipped = zip(alphabeticNumbers, numbers).map { $0 }

The value for zipped will be [("Three", 3), ("Five", 5), ("Nine", 9), ("Ten", 10)].

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset