<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 17, 2017 at 9:20 AM Ross O&#39;Brien &lt;<a href="mailto:narrativium%2Bswift@gmail.com">narrativium+swift@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">(0..&lt;3).map{ _ in UIView() } - map already returns an Array.<div><br><div>Array((0..&lt;3).map{ _ in UIView() }) is redundant.</div></div></div></blockquote><div><br></div><div>Ah, right, thanks for pointing that out. I couldn&#39;t remember off the top of my head whether it returned an array or some kind of special sequence type that would need to be converted over.</div><div><br></div><div>In that case, I still think the map version wins—it&#39;s very clear that a repeated *operation* is occurring, whereas the originally proposed @autoclosure version hides that very important semantic information.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I&#39;ve fallen foul before, of trying to create an array of six buttons and getting an array of one button six times; I think that should be easier. But if each button corresponds to an existing value or needs to be initialised based on its index in that array, map transposing values or indices into buttons is already covered.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 5:03 PM, Tony Allevato via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Couldn&#39;t this be rewritten more simply today as:<div><br></div><div>    Array((0..&lt;3).map { index in MyView(forIndex: index) })</div><div><br></div><div>And the version that doesn&#39;t need the index could be written:</div><div><br></div><div>    Array((0..&lt;3).map { _ in UIView() })</div><div><br></div><div>The AnyIterator approach posted above is also nice—I wouldn&#39;t have thought of that one. But I suppose that only works in the case where you don&#39;t need the index.</div><div><br></div><div>So the question is, should we increase the API surface of Array for something that (IMO) is already fairly straightforward to do? The nice thing about the approaches above is that they&#39;re composable. Array doesn&#39;t have to make any assumptions about closures or index arguments to those closures; it just takes a sequence and we already have primitives to construct sequences of new objects using .map. Array(repeating:count:) and repeatedElement(_:count:) are nice when the value being repeated is fixed, but I think once you start getting into questions like &quot;what if I need a different thing each time?&quot; or &quot;what if I need to involve the index as part of the elements?&quot; then it&#39;s better suited to compose the features already there to build something up than to add new APIs that try to cover each of these special cases.</div><div><br></div></div><div class="m_-3910698560844300130HOEnZb"><div class="m_-3910698560844300130h5"><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 17, 2017 at 8:40 AM Christopher Kornher via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><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>We might as well add the index to the call so elements can be created from other lists, etc.</div><div><br></div><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> Array(repeatedlyCalling: { (index:Int) in MyView( forIndex:index ) }, count: 3) // This might by syntactically correct...</div></div></div></div></div></div><div style="word-wrap:break-word"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div></div></div></div></div><div><br></div><br><div><blockquote type="cite"><div>On Aug 17, 2017, at 9:24 AM, Rob Mayoff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-3910698560844300130m_7752994478503109029m_-6561560767473454887Apple-interchange-newline"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Aug 17, 2017 at 7:04 AM, Robert Bennett via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div></div><div>Alternatively, instead of replacing the current definition with an autoclosure version, we could leave the current version in place and add a version taking a function. This could be especially useful when you’ve defined a function like `makeMySpecialKindOfButton() -&gt; UIButton` that does a lot of customization to an object before returning it.</div><div><br></div><div>Array(repeating: { return UIView() }, count: 3)</div><div>and</div><div>Array(repeating: <span style="background-color:rgba(255,255,255,0)">makeMySpecialKindOfButton, count: 3)</span></div></div></blockquote><div><br></div><div>This is still source-breaking, because an array of closures is legal. We need a different name to avoid breaking source:</div><div><br></div><div>    Array(repeatedlyCalling: { UIView() }, count: 3)</div><div> </div></div></div></div>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>
</div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
</blockquote></div></div>