<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=""><div class="">I never said a RangeReplaceableCollection shouldn’t be empty. I just think it’s strange that it requires an empty initialiser (while the Collection protocol doesn’t).</div><br class=""><div><blockquote type="cite" class=""><div class="">On 6 Jul 2016, at 16:33, Zhao Xin &lt;<a href="mailto:owenzx@gmail.com" class="">owenzx@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">N<div class="gmail_default" style="font-family:georgia,serif;display:inline">​o. You didn't catch what I meant. I meant it should be like an equation. ​If foo is a&nbsp;</div><span style="font-family:georgia,serif" class="">​</span><font face="georgia, serif" class="">RangeReplaceableCollection,<div class="gmail_default" style="font-family:georgia,serif;display:inline">​&nbsp;</div></font><span style="font-family:georgia,serif" class="">foo</span><font face="georgia, serif" class=""><div class="gmail_default" style="font-family:georgia,serif;display:inline">&nbsp;minus&nbsp;</div></font><span style="font-family:georgia,serif" class="">foo</span><font face="georgia, serif" class=""><div class="gmail_default" style="display:inline">&nbsp;equates&nbsp;zero, zero means an empty collection. Both side of the equation should be with the same unit, the unit is&nbsp;</div></font><span style="font-family:georgia,serif" class="">RangeReplaceableCollection.<div class="gmail_default" style="font-family:georgia,serif;display:inline">​ Below code also shows init() is useful in&nbsp;</div></span><font face="georgia, serif" class="">RangeReplaceableCollection.<div class="gmail_default" style="font-family:georgia,serif;display:inline">​​</div></font><div class=""><span style="font-family:georgia,serif" class=""><div class="gmail_default" style="font-family:georgia,serif;display:inline"><br class=""></div></span></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">var</span><span style="" class=""> foo = </span><span style="color:rgb(112,61,170)" class="">Array</span><span style="" class="">&lt;</span><span style="color:rgb(112,61,170)" class="">Int</span><span style="" class="">&gt;()</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">
</p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(79,129,135)" class="">foo</span><span style="" class="">.</span><span style="color:rgb(61,29,129)" class="">append</span><span style="" class="">(contentsOf: [</span><span style="color:rgb(39,42,216)" class="">2</span><span style="" class="">,</span><span style="color:rgb(39,42,216)" class="">4</span><span style="" class="">,</span><span style="color:rgb(39,42,216)" class="">6</span><span style="" class="">,</span><span style="color:rgb(39,42,216)" class="">8</span><span style="" class="">])</span></div></blockquote></blockquote>
<div class=""><div class=""><font face="georgia, serif" class=""><div class="gmail_default" style="font-family:georgia,serif;display:inline"><br class=""></div></font></div><div class=""><font face="georgia, serif" class=""><div class="gmail_default" style="font-family:georgia,serif;display:inline">​Zhaoxin</div></font></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Jul 6, 2016 at 10:07 PM, Tim Vermeulen <span dir="ltr" class="">&lt;<a href="mailto:tvermeulen@me.com" target="_blank" class="">tvermeulen@me.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You wouldn’t need an empty initialiser to remove all elements from a collection, right? You could just use `replaceRange` instead.<br class="">
<br class="">
&gt; Now I understood you concerns. Have you ever thought of if a non-empty RangeReplaceableCollection being removed all of its elements, which makes the collection to be an empty collection. That shouldn't change theRangeReplaceableCollection to be a non-RangeReplaceableCollection. Sothe empty collection must also be aRangeReplaceableCollection.<br class="">
&gt;<br class="">
&gt; &gt; init()<br class="">
&gt; (<a href="file:///Users/zhaoxin/Library/Application%20Support/Dash/DocSets/Apple_API_Reference/Apple_API_Reference.docset/Contents/Resources/Documents/" class="">file:///Users/zhaoxin/Library/Application%20Support/Dash/DocSets/Apple_API_Reference/Apple_API_Reference.docset/Contents/Resources/Documents/</a><a href="http://developer.apple.com/reference/swift/rangereplaceablecollection/1641467-init.html" rel="noreferrer" target="_blank" class="">developer.apple.com/reference/swift/rangereplaceablecollection/1641467-init.html</a>)&gt; Creates a new, empty collection.<br class="">
&gt;<br class="">
&gt; Zhaoxin<br class="">
<span class="">&gt;<br class="">
&gt; On Wed, Jul 6, 2016 at 9:09 PM, Tim Vermeulen&lt;<a href="mailto:tvermeulen@me.com" class="">tvermeulen@me.com</a>(mailto:<a href="mailto:tvermeulen@me.com" class="">tvermeulen@me.com</a>)&gt;wrote:<br class="">
&gt; &gt; I’m not allowing generic subscripts. The collection is declared as `AnyIndexArray&lt;Index: Strideable, Element where Index.Stride == Int&gt;` and it can be subscripted with type `Index`.<br class="">
&gt; &gt;<br class="">
&gt; &gt; Either way, it’s not really important. I’m mostly wondering why RangeReplaceableCollection needs an empty initialiser.<br class="">
&gt; &gt;<br class="">
&gt; &gt; &gt;Then how you defined the index to conform toStrideable? Below code does work as it seams that you can't use generics in subscripts.<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;subscript&lt;T:Strideable&gt;(index:T) -&gt;Element<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;Zhaoxin<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
</span>&gt; &gt; &gt;On Wed, Jul 6, 2016 at 8:32 PM, Tim Vermeulen&lt;<a href="mailto:tvermeulen@me.com" class="">tvermeulen@me.com</a>(mailto:<a href="mailto:tvermeulen@me.com" class="">tvermeulen@me.com</a>)(mailto:<a href="mailto:tvermeulen@me.com" class="">tvermeulen@me.com</a>)&gt;wrote:<br class="">
<span class="">&gt; &gt; &gt;&gt;<br class="">
&gt; &gt; &gt;&gt;&gt;On 6 Jul 2016, at 14:03, Zhao Xin&lt;<a href="mailto:owenzx@gmail.com" class="">owenzx@gmail.com</a>(mailto:<a href="mailto:owenzx@gmail.com" class="">owenzx@gmail.com</a>)(mailto:<a href="mailto:owenzx@gmail.com" class="">owenzx@gmail.com</a>)&gt;wrote:<br class="">
&gt; &gt; &gt;&gt;&gt;According to the document of Swift 3, Array has already conformed protocolRangeReplaceableCollection.<br class="">
&gt; &gt; &gt;&gt;<br class="">
&gt; &gt; &gt;&gt;That’s exactly why I also want to conform my wrapper to that protocol? I think there’s a misunderstanding. I’m making a collection that can be subscripted with any index (that conforms to Strideable), but behaves like an array otherwise.<br class="">
&gt; &gt; &gt;&gt;<br class="">
&gt; &gt; &gt;&gt;&gt;<br class="">
&gt; &gt; &gt;&gt;&gt;Zhaoxin<br class="">
&gt; &gt; &gt;&gt;&gt;<br class="">
</span><span class="">&gt; &gt; &gt;&gt;&gt;On Wed, Jul 6, 2016 at 7:09 PM, Tim Vermeulen via swift-users&lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>(mailto:<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>)(mailto:<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>)&gt;wrote:<br class="">
&gt; &gt; &gt;&gt;&gt;&gt;RangeReplaceableCollection has three initialisers: init(), init(_:) and init(repeating:count:). The latter two are implemented using the empty initialiser. But why are these initialisers part of this particular protocol? As far as I can tell, no other methods of this protocol depend on these initialisers. The requirement of the empty initialiser makes it impossible to have a collection conform to this protocol that needs additional data for its initialisation.<br class="">
&gt; &gt; &gt;&gt;&gt;&gt;<br class="">
&gt; &gt; &gt;&gt;&gt;&gt;For instance, I was making an array that works with any Strideable indices, not just integers. A startIndex is needed for its initialisation, so I can’t really conform it to RangeReplaceableCollection. If I do it anyways (with a fatalError() in the required empty initialiser) everything seems to work just fine, except for the protocol’s three initialisers.<br class="">
&gt; &gt; &gt;&gt;&gt;&gt;<br class="">
&gt; &gt; &gt;&gt;&gt;&gt;Perhaps these initialisers should be moved to a (possible new) different protocol?<br class="">
&gt; &gt; &gt;&gt;&gt;&gt;_______________________________________________<br class="">
&gt; &gt; &gt;&gt;&gt;&gt;swift-users mailing list<br class="">
</span>&gt; &gt; &gt;&gt;&gt;&gt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>(mailto:<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>)(mailto:<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>)<br class="">
&gt; &gt; &gt;&gt;&gt;&gt;<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class="">
&gt; &gt; &gt;&gt;&gt;<br class="">
&gt; &gt; &gt;&gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt; &gt; &gt;<br class="">
&gt;<br class="">
&gt;<br class="">
&gt; </blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>