<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="">This is the kind of thing that I'd let live in a library and consider importing into the standard if a lot of people use it.<br class=""><div class="">
<br class="Apple-interchange-newline"><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;" class="">Félix</span>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Le 6 avr. 2016 à 09:13:41, Milos Rankovic via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</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="">Checking for divisibility is very common:<div class=""><br class=""></div><div class=""> <span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(255, 38, 0);">21</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px;"> % </span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(255, 38, 0);">3</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px;"> == </span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(255, 38, 0);">0</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px;"> </span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(203, 203, 203);">// true</span></div><div class=""><br class=""></div><div class="">In fact, this is such a common use of the `<span class="" style="font-family: 'Source Code Pro'; font-size: 12px;">%</span>` operator that the `<span class="" style="font-family: 'Source Code Pro'; font-size: 12px;">== </span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(255, 38, 0);">0</span>` side of the expression seems distracting in this use case. For quite a while now, I’ve been using a custom operator for this, which is steadily growing on me:</div><div class=""><br class=""></div><div class=""> <span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(255, 38, 0);">21</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px;"> </span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(145, 84, 15);">%==</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px;"> </span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(255, 38, 0);">3</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px;"> </span><span class="" style="color: rgb(203, 203, 203); font-family: 'Source Code Pro'; font-size: 12px;">// true</span></div><div class=""><br class=""></div><div class="">… which also allows me to overload it for sequences:</div><div class=""><br class=""></div><div class=""> <span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(255, 38, 0);">21</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px;"> </span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(145, 84, 15);">%==</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px;"> [</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(255, 38, 0);">7</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px;">, </span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(255, 38, 0);">3</span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px;">] </span><span class="" style="font-family: 'Source Code Pro'; font-size: 12px; color: rgb(203, 203, 203);">// true</span></div><div class=""><br class=""></div><div class="">(If I’m inadvertently misusing this mailing list to share such a minor idea, please tell me off so that I can learn not to do it again!)</div><div class=""><br class=""></div><div class="">milos</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>