Swift Standard Library: Zip2

There are lots useful of type, functions, protocols and classes in the Swift Standard Library, many of which have little or no documentation. After finding Swifter a website that extracts what little documentation exists, I have been trying to come up with example code demonstrating them. This is the first post in what I hope will be a series of posts.


Given two sequences [ x0, x1 ... xn ] and [ y0, y1 ... yn ], Zip2 produces the sequence [ (x0, y0), (x1, y1) ... (xn, yn) ].

For example, suppose you are writing a Spanish verb conjugator, and you want to prepend the personal pronouns to each form of the verb, you could write:

Or if you are more mathematically minded you could implement a dot product routine:

Download the Playground

The source for this and all other playgrounds in this series can be found on Github in the SwiftStandardLibraryPlaygrounds repository.

About idz

A professional software engineer dabbling in iOS app development.
This entry was posted in Swift, Tutorial. Bookmark the permalink.

Leave a Reply