[swift-evolution] Proposal: Add SequenceType.first

Kevin Ballard kevin at sb.org
Sun Jan 3 00:50:45 CST 2016


On Sat, Jan 2, 2016, at 09:50 PM, Brent Royal-Gordon via swift-evolution wrote:
> > If I don’t sound sympathetic, it’s because nobody has shown a use-case for this functionality, and until I see one I am going to have a hard time believing there’s a problem worth solving.  If you want to make the case that we need something like this, please show me why. 
> 
> Didn't this thread start off with a use case?
> 
> 	seq.lazy.filter(predicate).first		// is not actually lazy, and Swift provides no good way to do this
> 
> One way to fix this is to add `first` to `SequenceType`, but it feels strange for a property to potentially consume part of the sequence. `buffered` ultimately has the same problem. By representing this as a function, it at least looks like something that might have side effects.

`buffered` is no more problematic than `lazy` is. In fact, calling `buffered` actually doesn't have any side-effects at all (it can avoid fetching the first element until you call `first` on the result of `buffered`).

-Kevin


More information about the swift-evolution mailing list