<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="">This is one of those things that takes very little to add, I would use it if it existed (having written workarounds), but it isn't horrible not having it there.&nbsp;</div><div class=""><br class=""></div><div class="">The only place off the top of my head that I consistently use it for is wrapping, but that's a really nice use case.</div><div class=""><br class=""></div><div class="">-- E</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On May 21, 2016, at 2:22 PM, Adam Nemecek 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=""><div dir="ltr" class=""><div class="">Hello,&nbsp;</div><div class=""><br class=""></div><div class="">I think that Swift could use the 'double modulo' operator which is for example in CoffeeScript (some discussion can be found here <a href="https://github.com/jashkenas/coffeescript/issues/1971" class="">https://github.com/jashkenas/coffeescript/issues/1971</a>).</div><div class=""><br class=""></div><div class="">This operator, unlike normal modulo, takes sign from the divisor, not the dividend e.g. -10 % 3 == -1, but -10 %% 3 == 2.</div><div class=""><br class=""></div><div class="">In practice, this operator is useful for 'cyclical' indexing. For example, it would be useful for calculating the real index into a collection when we are using an index outside of the range of valid indices and could be used to index into a collection using a negative index à la Python and Ruby (where [1,2,3,4][-1] == 4).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">The implementation would probably be something along these lines:</div><div class=""><br class=""></div><div class="">infix operator %% {</div><div class="">&nbsp; associativity left</div><div class="">&nbsp; precedence 150</div><div class="">}</div><div class=""><br class=""></div><div class="">func %%&lt;T: IntegerArithmeticType&gt;(lhs:T, rhs:T) -&gt; T {</div><div class="">&nbsp; return (lhs % rhs + rhs) % rhs</div><div class="">}</div><div class=""><br class=""></div><div class="">If accepted, this could be later incorporated into a method or operator that works directly with collections using their count property.&nbsp;</div><div class="">Maybe the syntax could be something like [1,2,3,4] %% -1 == 4.</div><div class=""><br class=""></div><div class="">Ideas, suggestions?</div></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=""></body></html>