[swift-evolution] [Pitch] Remove destructive consumption from Sequence

Russ Bishop xenadu at gmail.com
Sun Jun 26 17:41:09 CDT 2016


> On Jun 23, 2016, at 12:26 AM, Jonathan Hull via swift-evolution <swift-evolution at swift.org> wrote:
> 
> What are the actual use-cases where people have needed destructive iterators?  Every time I have thought I wanted it, I ended up wanting multi-pass later.  For example, I had a sequence of random numbers, but ended up having to build a random hash instead so I could reliably re-create that sequence.  The other use-cases I can think of (e.g. markov-chains) would probably end up needing repeatability at some point as well.
> 
> The only thing I can think of without an eventual multi-pass requirement would be reading in an input or signal of some sort.
> 
> Thanks,
> Jon

I use it in a LazyRowSequence<T: SqlModelConvertible> where querying Sqlite in WAL mode allows multiple concurrent readers to get point-in-time snapshots of the database. The query can’t be replayed without buffering all the rows in memory because Sqlite’s step functions are not bi-directional. In some cases we are talking about tens of thousands of rows (or even hundreds of thousands) and the ability to avoid buffering them is a feature, not a bug.

Sequence is the stream of things you can iterate over; that’s the only real promise it makes. If you want repeated iteration use a Collection.

I’m sure someone has a use for a stream of values that can’t be buffered but can be iterated over multiple times, but is that common enough to warrant redesigning the entire sequence/collection/iterator hierarchy?


Russ


More information about the swift-evolution mailing list