[swift-evolution] Proposal: Add SequenceType.first
kevin at sb.org
Sat Jan 2 21:28:01 CST 2016
On Sat, Jan 2, 2016, at 07:17 PM, Dave Abrahams wrote:
>> But since it's a CollectionType, you need to preserve the ability to
>> access older values.
> Not once you replace it with a slice of itself.
Ah I see, I missed that subtlety. Or more specifically, when you first
said "slice" I was thinking of the Slice struct, but if you implement
slicing by hand then you can do this just fine.
>> So the only way to actually have this be a CollectionType is to
>> buffer the entire sequence up to the highest-accessed index.
>> Of course, your use-case of processing a stream with some amount of
>> lookahead and throwing away the old data actually sounds like
>> something a "BufferedSequence" might provide. Or actually, a
>> "BufferedGenerator", because the only way to process a sequence is
>> with a generator and so all a "BufferedSequence" would really do is
>> just give you a "BufferedGenerator" from its generate() method.
> I’m quite certain this is buildable. I’ve got my hands full at the
> moment or I’d create a prototype…
Now that I realize exactly what you meant, it should indeed be
buildable. Though short of requiring the user to provide it, I'm not
sure how to pick an appropriate chunk size.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution