O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)].

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required