A Swift Sequence may represent many kinds of sequential elements: natural numbers, word from a source text, hues in a color wheel, bytes in a memory allocation, and so forth. It is natural and common to stride through sequences, especially those that aren't necessarily numerical in nature. A stride allows you to collect or consume spaced-out values at a faster pace. For example, you might want to look at "every 4th byte" to process alpha channels, "every other row" for spreadsheet highlights, or "every two hundredth word" for frequency analysis.
Swift's built-in stride functions are number based. They are useful for striding through integer and floating point numbers. They can act as integer-based collection indices. These functions aren't, however, suitable for skipping through non-numerical, possibly infinite sequences, which may or may not be multipass or otherwise indexable.
For example, you might create a color progression Sequence and parameterize how quickly to procede from, for example, red through orange, yellow, green, and beyond.
You cannot use indexing features without creating an intermediate array.
This proposal extends Sequence to introduce strides across any base.
so would it just discard all the “filler” values if the sequence is single-pass? this seems pretty unperformant when using it on iterators of a collection that actually supports random access. You would be much better off just indexing into the collection directly.
Yeah, it would be worth adding a specialization for RandomAccessCollection. There are lots of sequences and collections that don't support random access that we still might want to stride through, though — we should support them.