<div dir="ltr">Couldn't this be rewritten more simply today as:<div><br></div><div> Array((0..<3).map { index in MyView(forIndex: index) })</div><div><br></div><div>And the version that doesn't need the index could be written:</div><div><br></div><div> Array((0..<3).map { _ in UIView() })</div><div><br></div><div>The AnyIterator approach posted above is also nice—I wouldn't have thought of that one. But I suppose that only works in the case where you don'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're composable. Array doesn'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 "what if I need a different thing each time?" or "what if I need to involve the index as part of the elements?" then it'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><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 17, 2017 at 8:40 AM Christopher Kornher via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> 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 <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_-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"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></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() -> 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>