[swift-evolution] [Idea] Add an (Index, Element) sequence to CollectionType

Brent Royal-Gordon brent at architechies.com
Mon Dec 28 00:42:35 CST 2015

> What you're asking for can already be done with `zip(col.indices, col)`. And in my experience the need for this sort of thing is rare enough that there's no need to have a dedicated property for it in the stdlib. The few times that I've needed this sort of thing, I've always just said
> for index in col.indices {
>     let elt = col[index]
>     // ...
> }
> and that's pretty simple. But if I ever did need to map it, I'd just use the aforementioned zip() expression. 

I know the zip trick and have used it several times. In one project, I used it frequently enough that I created an extension. Personally, I would like to see a more convenient way to do this, although it's not that strong of a preference.

Brent Royal-Gordon

More information about the swift-evolution mailing list