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

2015-12-31 Thread Dave Abrahams via swift-evolution
> On Dec 29, 2015, at 8:06 AM, Wallacy via swift-evolution > wrote: > > I believe that the current behavior was thought when Slices had indices > starting with zero. The current behavior was intentional (and intentionally left as-is when array slices changed);

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

2015-12-29 Thread Wallacy via swift-evolution
FWIW: In cases like this, just remember call ".reverse()" and remove from the back. var array = [ "", "a", "b", "c", "", "d" ] for (index, element) in array.enumerate().reverse() { if element == "" { array.removeAtIndex(index) } } print(array) // ["a", "b", "c", "d"] zip is

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

2015-12-28 Thread Dany St-Amant via swift-evolution
The original example contains a bug which is present on all looping version/alternative due to the mutating nature of the array. Using the zip implementation: var array = [ "", "a", "b", "c", "", "d" ] var secondHalf = array[array.count/2..

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

2015-12-28 Thread Kevin Ballard via swift-evolution
What you describe isn't a bug in the implementation, it's a bug in the expectation that you can mutate an array that you're iterating over. With any other collection, the mutation would actually invalidate the index. It so happens that Arrays use Int as their index, so they can't really be

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

2015-12-27 Thread Kevin Ballard via swift-evolution
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

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

2015-12-27 Thread Brent Royal-Gordon via swift-evolution
> 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 >