On this series we’ve done a number of “deep dives” to really analyze a topic. Things like exploring the map
function to see that it’s a very universal idea and we should be comfortable defining it on our own types. And things like “contravariance”, which is kind of unintuitive at first but is really quite handy.
This often helps us see something we think we’re familiar with in a new light, or helps us see something that is very unintuitive but become comfortable with it because we develop ways to concisely manage it and transform it.
We’re doing another one of those today, and this time it’s the zip
function. You’ve probably used zip
a few times in your every day coding, and you probably thought it was pretty handy. But what we want to show people is that it’s a generalization of something you are already familiar with, but you may have never thought of it like this before. And once you see this generalization it really helps unify a bunch of disparate ideas.
Let’s begin by exploring the zip
that comes with Swift’s standard library.