<div dir="ltr"><div>Hello, </div><div><br></div><div>I think that Swift could use the &#39;double modulo&#39; operator which is for example in CoffeeScript (some discussion can be found here <a href="https://github.com/jashkenas/coffeescript/issues/1971">https://github.com/jashkenas/coffeescript/issues/1971</a>).</div><div><br></div><div>This operator, unlike normal modulo, takes sign from the divisor, not the dividend e.g. -10 % 3 == -1, but -10 %% 3 == 2.</div><div><br></div><div>In practice, this operator is useful for &#39;cyclical&#39; 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><br></div><div><br></div><div>The implementation would probably be something along these lines:</div><div><br></div><div>infix operator %% {</div><div>  associativity left</div><div>  precedence 150</div><div>}</div><div><br></div><div>func %%&lt;T: IntegerArithmeticType&gt;(lhs:T, rhs:T) -&gt; T {</div><div>  return (lhs % rhs + rhs) % rhs</div><div>}</div><div><br></div><div>If accepted, this could be later incorporated into a method or operator that works directly with collections using their count property. </div><div>Maybe the syntax could be something like [1,2,3,4] %% -1 == 4.</div><div><br></div><div>Ideas, suggestions?</div></div>