<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="">On Dec 29, 2015, at 2:37 PM, David Waite via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">The rest are as follows:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">╔════════════╦═════════════════╦═══════════════╦═════════════════╦════════════════════╗</font></div><div class=""><font face="Menlo" class="">║ <b class="">Type </b>&nbsp; &nbsp; &nbsp; ║ <b class="">Index* &nbsp;&nbsp;</b> &nbsp; &nbsp; &nbsp; ║ <b class="">Key &nbsp;</b> &nbsp; &nbsp; &nbsp; &nbsp; ║ <b class="">Value &nbsp;</b> &nbsp; &nbsp; &nbsp; &nbsp; ║ <b class="">Element**</b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ║</font></div><div class=""><font face="Menlo" class="">╠════════════╬═════════════════╬═══════════════╬═════════════════╬════════════════════╣</font></div><div class=""><font face="Menlo" class="">║ <b class="">Array &nbsp;</b> &nbsp; &nbsp;║ 0-based offset &nbsp;║ N/A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ║ N/A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ║ Generic "T" &nbsp; &nbsp; &nbsp; &nbsp;║</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 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ║ N/A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ║ Generic "T" &nbsp; &nbsp; &nbsp; &nbsp;║</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 class=""><br class=""></div><div class="">* Index is declared on CollectionType</div><div class="">** Element is declared on GeneratorType and referenced by SequenceType</div><div class=""><br class=""></div><div class="">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>&nbsp;AssociativeCollectionType :&nbsp;<span style="color: rgb(97, 34, 174);" class="">CollectionType</span>&nbsp;{</div><div style="margin: 0px; line-height: normal; color: rgb(195, 34, 117); font-size: 12px;" class=""><span style="" class="">&nbsp; &nbsp;&nbsp;</span>typealias<span style="" class="">&nbsp;Key</span></div><div style="margin: 0px; line-height: normal; font-size: 12px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(195, 34, 117);" class="">typealias</span>&nbsp;Value</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(195, 34, 117);" class="">typealias</span>&nbsp;Element = (Key, Value)</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(195, 34, 117);" class="">typealias</span>&nbsp;KeySequenceType = AnySequence&lt;Key&gt;</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(195, 34, 117);" class="">typealias</span>&nbsp;ValueSequenceType = AnySequence&lt;Value&gt;</div><div style="margin: 0px; line-height: normal; min-height: 21px; font-size: 12px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-size: 12px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(195, 34, 117);" class="">var</span>&nbsp;keys:&nbsp;<span style="color: rgb(97, 34, 174);" class="">KeySequenceType</span>&nbsp;{&nbsp;<span style="color: rgb(195, 34, 117);" class="">get</span>&nbsp;}</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(195, 34, 117);" class="">var</span>&nbsp;values:&nbsp;<span style="color: rgb(97, 34, 174);" class="">ValueSequenceType</span>&nbsp;{&nbsp;<span style="color: rgb(195, 34, 117);" class="">get</span>&nbsp;}</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(195, 34, 117);" class="">subscript</span>&nbsp;(key:&nbsp;<span style="color: rgb(97, 34, 174);" class="">Key</span>) -&gt;&nbsp;<span style="color: rgb(97, 34, 174);" class="">Value</span>? {&nbsp;<span style="color: rgb(195, 34, 117);" class="">get</span>&nbsp;<span style="color: rgb(195, 34, 117);" class="">set</span>&nbsp;}</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(195, 34, 117);" class="">func</span>&nbsp;indexForKey(key:<span style="color: rgb(97, 34, 174);" class="">Key</span>) -&gt;&nbsp;<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="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(195, 34, 117);" class="">mutating</span>&nbsp;<span style="color: rgb(195, 34, 117);" class="">func</span>&nbsp;removeValueForKey(key:&nbsp;<span style="color: rgb(97, 34, 174);" class="">Key</span>) -&gt;&nbsp;<span style="color: rgb(97, 34, 174);" class="">Value</span>?</div><div style="margin: 0px; line-height: normal; font-size: 12px;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(195, 34, 117);" class="">mutating</span>&nbsp;<span style="color: rgb(195, 34, 117);" class="">func</span>&nbsp;updateValue(value:&nbsp;<span style="color: rgb(97, 34, 174);" class="">Value</span>, forKey key:&nbsp;<span style="color: rgb(97, 34, 174);" class="">Key</span>) -&gt;&nbsp;<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></div></div></div></blockquote><div><br class=""></div>What is the use-case for this protocol?</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><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="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=JfMPa-2F7wwZPzsZ3QKA8NjtONIYX4SjbWuUxtpfsTY2iEpGlxmCbpoqe-2B5-2F4igAkfn9x-2BzfVZL4j5kpYZ7-2FHdc6z6m-2B1juxIG14jCgyr782W5rCBAy62PMk40EWpuV5ZiRnCZBKZkyf32kZLT7s8A-2F88ND5nMP9HVzkHLXzG3yC4G4sInB-2FQ0le2PVS3OjAyYoN-2BGMwH232MXn-2FINP7RVjHDCI06-2BOR8-2Fp1rxvhjsMkw-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""><div class="">
-Dave
</div>
<br class=""></body></html>