[swift-evolution] [Pitch] Improve `init(repeating:count)`

Jonathan Hull jhull at gbis.com
Thu Aug 17 11:00:48 CDT 2017


The closure should go on the end though…

> On Aug 17, 2017, at 8:40 AM, Christopher Kornher via swift-evolution <swift-evolution at swift.org> wrote:
> 
> We might as well add the index to the call so elements can be created from other lists, etc.
> 
>  Array(repeatedlyCalling: { (index:Int) in MyView( forIndex:index ) }, count: 3) // This might by syntactically correct...
> 
> 
> 
>> On Aug 17, 2017, at 9:24 AM, Rob Mayoff via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> On Thu, Aug 17, 2017 at 7:04 AM, Robert Bennett via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 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.
>> 
>> Array(repeating: { return UIView() }, count: 3)
>> and
>> Array(repeating: makeMySpecialKindOfButton, count: 3)
>> 
>> This is still source-breaking, because an array of closures is legal. We need a different name to avoid breaking source:
>> 
>>     Array(repeatedlyCalling: { UIView() }, count: 3)
>>  
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170817/3d37dcc3/attachment.html>


More information about the swift-evolution mailing list