An implementation of a free zip function that will take three Sequence types and return another Sequence whose elements are each three-item tuples built from the elements of three underlying sequences. It's the zip from the standard library but for three sequences.
The advantages of working in a type-safe language extend beyond the compiler complaining that it received an Double but expected an Int. Developers can use the Swift type system to enforce complex invariants rather than relying on mere conventions or other fragile means, but reaping the benefits requires some forethought and of bit careful design. I use an example modeling a network connection to illustrate this idea.
Swift 4 adds the ability to easily archive struct and enum types that implement the Codable protocol, but default support for enums is limited to those with prepopulated default values (raw values). Conforming an enum with associated values to the Codable protocol involves extra work, and it is the purpose of this article to show how this could be done.
In this post, I’m going to create superficially real-looking text using a Markoff chain. I'll do it in Swift, and explain in particular various ways of using Sequence and IteratorProtocol to solve the problem.