[swift-evolution] Proposal: Add SequenceType.first

Dave Abrahams dabrahams at apple.com
Sat Jan 2 21:04:20 CST 2016

> On Jan 2, 2016, at 12:13 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> Why should we absolutely add methods with unclear meanings or behavior, when there are already perfectly clear, if verbose, alternatives? seq.generate().next() may not be nice, but no one can get fooled by it.
> Well, for one thing, because it doesn't work. You can't call a mutating method directly on a return value without assigning it to a variable first. And put simply, a temporary variable seems a bridge too far to me.

For a possibly-mutating operation, I think it’s perfectly appropriate that you have to create an intermediate variable.  If you want to create an extension with a “func possiblyConsumeFirst() -> Generator.Element”, you are welcome to do so; that’s what extensions are for.  IMO the standard library should not hide volatile sequence consumption under a property access.

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. 


More information about the swift-evolution mailing list