Lazy Permutations in Swift
Why is our generic type
Xan iterator but we forceYto conform toCollection? If you look at the nested loop in our naive example above, you’ll see that while we iterate overxsonly once, we actually loop overysa number of times (anxs.countnumber of times, to be precise).
IteratorProtocolallows us to iterate over a set exactly once, so it’s perfect for ourXtype. But onlyCollectionguarantees us the ability to non-destructively traverse a sequence over and over. SoYmust be a little more constrained.[…]
And so, finally, we can lazily iterate over every ordered pair of our collections — all while only storing the collections themselves, not their product.
1 Comment RSS · Twitter
Wow, his articles are very good to learn new things about both Swift and Mac programming. Nearly all of the "Tips & Tricks" posts are very helpful to me. Only drawback is that his blogging site doesn't seem to provide an overview of all articles - instead one has to scroll down on a huge page to find each one's headline.