So, what are we to do? Parsing this string with map
and flatMap
gets the job done, but it isn’t super nice. Luckily, there’s a third operation that sits right in between map
and flatMap
. We talked about this very topic over the course of 3 entire episodes on Point-Free (1, 2, 3), and it naturally encompasses the idea of “context independence” computation, and it is none other than zip
. It allows you to take multiple generic values and combine them into a single generic value. The Swift standard library defines zip
on arrays, but in our previous episodes we showed that it makes sense to define zip
on many more types, such as optionals, results, validated values, lazy values, and asynchronous values.