[swift-evolution] API Guidelines: dropFirst?
Brent Royal-Gordon
brent at architechies.com
Thu Jun 16 06:56:11 CDT 2016
> That said I actually think it’s useful to have these methods slightly different as if I understand them correctly they’re not strictly non-mutating; a Sequence doesn’t guarantee that it can be consumed over and over without changing, as it could represent a buffer or some other construct that’s consumed as it’s accessed, so calling dropFirst() on a sequence, then calling it again on the same sequence may not yield the same result both times, for that you want a Collection (or a specific sequence implementation with well defined behaviour), but for a generic sequence I don’t think you can trust the method to be non-mutating unless you know what the sequence is backed by, so it shouldn’t follow the rule for non-mutating methods.
`dropFirst()`, like all `Sequence` APIs, works perfectly and reliably as long as you only access the contents of the `Sequence` once. Attempting to iterate the `Sequence` more than once may or may not work, so you shouldn't do it without static knowledge of the concrete type's behavior (for instance, knowledge that it's actually a `Collection`).
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list