<div dir="ltr">On Thu, Aug 17, 2017 at 8:06 PM, Erica Sadun <span dir="ltr">&lt;<a href="mailto:erica@ericasadun.com" target="_blank">erica@ericasadun.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Aug 17, 2017, at 6:56 PM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="m_5899191079070621741Apple-interchange-newline"><div><div dir="ltr">On Thu, Aug 17, 2017 at 7:51 PM, Erica Sadun <span dir="ltr">&lt;<a href="mailto:erica@ericasadun.com" target="_blank">erica@ericasadun.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>What people are doing is taking a real set of values (1, 2, 3, 4, 5, for example), then discarding them via `_ in`, which is different from `Void -&gt; T` or `f(x) = 0 * x`. The domain could just as easily be (Foo(), &quot;b&quot;, 💩,  UIColor.red, { x: Int in x^x }). There are too many semantic shifts away from &quot;I would like to collect the execution of this closure n times&quot; for it to sit comfortably.</div></div></blockquote><div><br></div><div>What arguments might help to alleviate this discomfort? Clearly, functions exist that can map this delightfully heterogeneous domain to some sort of range that the user wants. Would you feel better if we wrote instead the following?</div><div><br></div><div>```</div><div>repeatElement((), count: 5).map { UIView() }</div><div>```</div></div></div></div></div></blockquote><div><br></div></span>My favorite solution is the array initializer. Something along the lines of `Array&lt;T&gt;(count n: Int, generator: () -&gt; T)`. I&#39;m not sure it _quite_ reaches standard library but I think it is a solid way to say &quot;produce a collection with a generator run n times&quot;. It&#39;s a common  task. I was asking around about this, and found that a lot of us who work with both macOS and iOS and want to stress test interfaces do this very often. Other use cases include &quot;give me n random numbers&quot;, &quot;give me n records from this database&quot;, etc. along similar lines.</div><div><br></div><div>The difference between this and the current `Array(repeating:count:)` initializer is switching the arguments and using a trailing closure  (or an autoclosure) rather than a set value. That API was designed without the possibility that you might want to repeat a generator, so there&#39;s a bit of linguistic turbulence.</div></div></blockquote><div><br></div><div>...but, again, why would such an API be superior to `map`, which is already widely used and clear? My point above was that, if your problem with using `(0..&lt;5).map { _ in UIView() }` is the discarding of a set of values (which I argue is semantically unproblematic in the first place, since it&#39;s still mapping from a domain to a range), then `repeatElement((), count: 5).map { UIView() }` produces the same result without violating your stipulated semantics.</div></div><br></div></div>