<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">Anyway, it would not be correct to ".enumerate()" returns (Index, Element) instead of (n, Element)?</div><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><div class=""><br class=""></div><div class="">I believe that the current behavior was thought when Slices had indices starting with zero.<br class=""></div><div class=""><b class=""><br class=""></b></div></div></div></div></blockquote><div><br class=""></div><div>The behavior of enumerate is easiest to explain when you give everything a name and lay them all out on the table: In particular, there is a difference between a Counter, an Index, a Key, a Value, and an Element.</div><div><br class=""></div><div>Enumerate always works in terms of adding a counter, not an index. It was perhaps better served as a global method, since one cannot really improve its default implementation.</div><div><br class=""></div><div>The rest are as follows:</div><div><br class=""></div><div><div class=""><font face="Menlo" class="">╔════════════╦═════════════════╦═══════════════╦═════════════════╦════════════════════╗</font></div><div class=""><font face="Menlo" class="">║ <b class="">Type </b> ║ <b class="">Index* </b> ║ <b class="">Key </b> ║ <b class="">Value </b> ║ <b class="">Element**</b> ║</font></div><div class=""><font face="Menlo" class="">╠════════════╬═════════════════╬═══════════════╬═════════════════╬════════════════════╣</font></div><div class=""><font face="Menlo" class="">║ <b class="">Array </b> ║ 0-based offset ║ N/A ║ N/A ║ Generic "T" ║</font></div><div class=""><font face="Menlo" class="">╠════════════╬═════════════════╬═══════════════╬═════════════════╬════════════════════╣</font></div><div class=""><font face="Menlo" class="">║ <b class="">ArraySlice</b> ║ non-zero offset ║ N/A ║ N/A ║ Generic "T" ║</font></div><div class=""><font face="Menlo" class="">╠════════════╬═════════════════╬═══════════════╬═════════════════╬════════════════════╣</font></div><div class=""><font face="Menlo" class="">║ <b class="">Dictionary</b> ║ DictionaryIndex ║ Generic "Key" ║ Generic "Value" ║ Tuple (Key, Value) ║</font></div><div class=""><font face="Menlo" class="">╚════════════╩═════════════════╩═══════════════╩═════════════════╩════════════════════╝</font></div></div><div><br class=""></div><div>* Index is declared on CollectionType</div><div>** Element is declared on GeneratorType and referenced by SequenceType</div><div><br class=""></div><div>That Array [T] does not behave like a Dictionary [Int:T] is possibly a sign that an AssociativeCollectionType is needed, something like:</div><div class=""><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""><span style="color: rgb(195, 34, 117);" class="">protocol</span> AssociativeCollectionType : <span style="color: rgb(97, 34, 174);" class="">CollectionType</span> {</div><div style="margin: 0px; line-height: normal; color: rgb(195, 34, 117); font-size: 12px;" class=""><span style="color: rgb(0, 0, 0);" class=""> </span>typealias<span style="color: rgb(0, 0, 0);" class=""> Key</span></div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""> <span style="color: rgb(195, 34, 117);" class="">typealias</span> Value</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""> <span style="color: rgb(195, 34, 117);" class="">typealias</span> Element = (Key, Value)</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""> <span style="color: rgb(195, 34, 117);" class="">typealias</span> KeySequenceType = AnySequence<Key></div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""> <span style="color: rgb(195, 34, 117);" class="">typealias</span> ValueSequenceType = AnySequence<Value></div><div style="margin: 0px; line-height: normal; min-height: 21px; font-size: 12px;" class=""> <br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""> <span style="color: rgb(195, 34, 117);" class="">var</span> keys: <span style="color: rgb(97, 34, 174);" class="">KeySequenceType</span> { <span style="color: rgb(195, 34, 117);" class="">get</span> }</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""> <span style="color: rgb(195, 34, 117);" class="">var</span> values: <span style="color: rgb(97, 34, 174);" class="">ValueSequenceType</span> { <span style="color: rgb(195, 34, 117);" class="">get</span> }</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""> <span style="color: rgb(195, 34, 117);" class="">subscript</span> (key: <span style="color: rgb(97, 34, 174);" class="">Key</span>) -> <span style="color: rgb(97, 34, 174);" class="">Value</span>? { <span style="color: rgb(195, 34, 117);" class="">get</span> <span style="color: rgb(195, 34, 117);" class="">set</span> }</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""> <span style="color: rgb(195, 34, 117);" class="">func</span> indexForKey(key:<span style="color: rgb(97, 34, 174);" class="">Key</span>) -> <span style="color: rgb(97, 34, 174);" class="">Index</span></div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""><span style="color: rgb(97, 34, 174);" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""> <span style="color: rgb(195, 34, 117);" class="">mutating</span> <span style="color: rgb(195, 34, 117);" class="">func</span> removeValueForKey(key: <span style="color: rgb(97, 34, 174);" class="">Key</span>) -> <span style="color: rgb(97, 34, 174);" class="">Value</span>?</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class=""> <span style="color: rgb(195, 34, 117);" class="">mutating</span> <span style="color: rgb(195, 34, 117);" class="">func</span> updateValue(value: <span style="color: rgb(97, 34, 174);" class="">Value</span>, forKey key: <span style="color: rgb(97, 34, 174);" class="">Key</span>) -> <span style="color: rgb(97, 34, 174);" class="">Value</span>?</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class="">}</div></div></div><div class=""><br class=""></div><div class="">Dictionary would support such a protocol directly. Array and ArraySlice (or even every CollectionType) might have a mapping function (lets bike shed “associative()” for now) to return an implementation of the interface, mapping:</div><div class=""><br class=""></div><div class=""><div class="">- AssociativeCollectionType.<b class="">Index</b> = old Index</div></div><div class="">- AssociativeCollectionType.<b class="">Key</b> = old Index</div><div class="">- AssociativeCollectionType.<b class="">Value</b> = old Element</div><div class="">- AssociativeCollectionType.<b class="">Element</b> = old (Index, Element)</div><div class=""><br class=""></div><div class="">So maybe:</div><div class=""><br class=""></div><div class="">for (index, element) in someArray.associative() { … }</div><div class=""><br class=""></div><div class="">would do what the original idea requested: provide a (Index, Element) sequence for CollectionTypes.</div><div class=""><br class=""></div><div class="">-DW</div></div><blockquote type="cite" class=""><div class=""></div></blockquote></div><br class=""></body></html>