<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="">I agree with both of you about the alternative implementations.<div class=""><br class=""></div><div class="">That’s exactly what I’d love to see integrated to the standard library like Ruby is here:<div class=""><a href="http://ruby-doc.org/core-2.2.4/Integer.html#method-i-times" class="">http://ruby-doc.org/core-2.2.4/Integer.html#method-i-times</a></div><div class=""><br class=""></div><div class="">My main problem is that it neither looks <b class="">clean</b> nor <b class="">readable</b> especially for beginners that there is an <i class="">underscore</i> in the closure. Also beginners often get confused with the number of times some code is run when <i class="">starting to count from 0</i> which is also why I think it shouldn’t appear. The .times method would solve both of these problems.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 18.12.2015 um 19:33 schrieb Etan Kissling <<a href="mailto:kissling@oberon.ch" class="">kissling@oberon.ch</a>>:</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="">
(or with a for in loop -- but i guess you have a reason for using .foreach)
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span>
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">
_</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">
in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">
0</span>..<<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5_000</span> {</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">
print</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"asdf"</span>)</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
}</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">
<blockquote type="cite" class="">
<div class="">On 18 Dec 2015, at 19:31, Etan Kissling via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class="">You don't need stride for this.</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> foo() {</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>..<<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5_000</span>).<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">forEach</span>
{ <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">
_</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">
in</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">
print</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"asdf"</span>)</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
}</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
}</div>
</div>
<div class=""><br class="">
</div>
<br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">On 18 Dec 2015, at 19:25, Cihat Gündüz via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Dear Swift-Community,
<div class=""><br class="">
</div>
<div class="">I’d like to propose an <b class="">addition of a useful method</b>, especially for beginners that also makes Swift much more readable in some situations: The addition of a .times method to Integer type(s).</div>
<div class=""><br class="">
</div>
<div class="">For example recently in one of my projects I wanted to test the scalability of an important piece of code and wrote this method:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">
func</span> testPerfQualityInPercentWithoutQualityImprovements() {</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class="">
<span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="" class="">.</span>measureBlock<span style="" class=""> {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">
let</span> expectedQuality = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">
33.33</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">
0</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">stride</span>(to:
<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">
5_000</span>, by: <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">
1</span>).<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">forEach </span>{
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">
_</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">
in</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">
XCTAssertEqualWithAccuracy</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">crossword</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">qualityInPercent</span>,
expectedQuality, accuracy: <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">
0.1</span>) </div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
} </div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
}</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
}</div>
</div>
<div class=""><br class="">
</div>
<div class="">As you can see what I basically wanted was to repeat the test some thousand times. I also like to use the Ruby language and one thing I love about it is that it has some really handy methods integrated to the language in situations like this which
make the code very readable and therefore fun to use.</div>
<div class=""><br class="">
</div>
<div class="">I’m an even bigger fan of Swift so I’d love to see such useful methods appear in Swift, too and this is the first I came across that I really missed. So I’m asking myself, what if I could write the same code above like this:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="color: rgb(187, 44, 162);" class="">func</span> testPerfQualityInPercentWithoutQualityImprovements() {</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class="">
<span style="" class=""> </span><span style="color: rgb(187, 44, 162);" class="">self</span><span style="" class="">.</span>measureBlock<span style="" class=""> {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="color: rgb(187, 44, 162);" class="">let</span> expectedQuality = <span style="color: rgb(39, 42, 216);" class="">33.33</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="color: rgb(39, 42, 216);" class="">5_000.times {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="color: rgb(49, 89, 93);" class="">XCTAssertEqualWithAccuracy</span>(<span style="color: rgb(187, 44, 162);" class="">self</span>.<span style="color: rgb(79, 129, 135);" class="">crossword</span>.<span style="color: rgb(79, 129, 135);" class="">qualityInPercent</span>,
expectedQuality, accuracy: <span style="color: rgb(39, 42, 216);" class="">0.1</span>) </div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
} </div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
}</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
}</div>
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-family: Helvetica; font-size: 12px;" class="">I think it could be added to the Swift standard library very easily (for example by using the .stride method like I used) without any side effects and has enough advantages to be part of Swift
itself. What do you think?</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-family: Helvetica; font-size: 12px;" class=""><br class="">
</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-family: Helvetica; font-size: 12px;" class="">I wish you all the best,</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-family: Helvetica; font-size: 12px;" class="">Cihat</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-family: Helvetica; font-size: 12px;" class=""><br class="">
</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-family: Helvetica; font-size: 12px;" class=""><br class="">
</span></div>
<div style="margin: 0px; line-height: normal;" class="">P.S.: This is my very first mail in such a mailing list so I did everything correctly. ^.^</div>
<div style="margin: 0px; line-height: normal;" class=""><br class="">
</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=tTTJ5sn5y0uc3ODSZa-2BndLNwXCDS7T2cq5OlDDhG0Rv24uhtvYv57b57RThnoUBESAxxMDy12HfxuT9sf9VVp3u-2BljgFoOV9Ju-2BtFhXXJ1d8nr-2FYw-2FUNbKUk26rHfCj9zunav26wrq76QmN2VjrXsxpGqGynDLjQOq3xzG0kPrAlahxwYVVKYxWr-2FixGS8o60s13y8Z-2BEl3Y7elh5Tr-2F9t3iW87Nn3MFjpz-2FOHvhx30-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="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</div>
</blockquote>
</div>
<br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=tTTJ5sn5y0uc3ODSZa-2BndLNwXCDS7T2cq5OlDDhG0Rudyoy59P95VIFCXE8vsNIm3CRv2xeSfRQi24G3J7csJAwXsAU0KgdqyUmTpkPgjbX8d25r2mfuva9tzq-2FUDdol4HlpIh-2BHPdrv3VJ3o4xk2ghsZ6aTSUz-2FXhHLeKnEcHzsL3XLw-2F2NTNaky7syxtgWh87TGLUN5goHMjwNXVFxk5QMxUtPLGjvJKyN7d4juEc-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="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div></blockquote></div><br class=""></div></div></body></html>