[swift-evolution] [Idea] Replace enumerate() with something more explicit

Andrew Bennett cacoyi at gmail.com
Fri Apr 15 20:49:10 CDT 2016

I support a fixed version. I don't think that's mutually exclusive with
removing enumerate.

This thread seems to be a result of a misused API, so I think it's
necessary to make it obvious when that API changes. I think we'd want a
period of deprecation with both enumerate() and a new (hopefully more clear
and concise) method, so that people can fix their code.

I think this would be a good change:

+ @available(*, deprecated, message="it will be removed in Swift 3")
  public func enumerate() -> EnumerateSequence<Self>
+ public func indexed() -> Zip2Sequence<Self.Index,Self> { return
zip(self.indices, self) }

On Sat, Apr 16, 2016 at 11:12 AM, Charles Srstka <cocoadev at charlessoft.com>

> On Apr 15, 2016, at 8:09 PM, Andrew Bennett via swift-evolution <
> swift-evolution at swift.org> wrote:
> I'm in support of a method of getting a sequence of (Index,Value) pairs
> (as you know from the other thread). I think I'm leaning toward option
> three if it's equivalent to `zip(self.indices, self)`, ideally as a concise
> property like keys/values on a Dictionary.
> I've been using zip in production. I presumed enumerate was intended for
> enumerating indices, and that it had just been forgotten when the slice
> changes went through. I'm in favour of removing it.
> Instead of removing it, how about just fixing it so that it returns the
> proper indexes rather than arbitrary numbers?
> Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160416/4bf7fe39/attachment.html>

More information about the swift-evolution mailing list