[swift-evolution] Proposal: Add function SequenceType.find()

Thorsten Seitz tseitz42 at icloud.com
Thu Feb 18 15:15:17 CST 2016


Thanks! The second version is my favorite, too.

-Thorsten 

> Am 18.02.2016 um 22:02 schrieb Trent Nadeau <tanadeau at gmail.com>:
> 
> Indeed. I quite like the second version.
> 
>> On Thu, Feb 18, 2016 at 4:01 PM, Thorsten Seitz <tseitz42 at icloud.com> wrote:
>> 
>>> Am 18.02.2016 um 20:36 schrieb Trent Nadeau via swift-evolution <swift-evolution at swift.org>:
>>> 
>>> I would prefer a label on the first parameter, since you're not finding the NSButton type but instead elements having the type of NSButton.
>>> 
>>> subviews.find(havingType: NSButton.self, matching: { $0.state == NSOnState })
>> 
>> To comply with the guidelines I would expect a phrase like
>> 
>> subviews.findElement(havingType: NSButton.self, matching: { $0.state == NSOnState })
>> subviews.find(instanceOf: NSButton.self, matching: { $0.state == NSOnState })
>> 
>> -Thorsten 
>> 
>>> 
>>>> On Thu, Feb 18, 2016 at 4:37 AM, Marco Masser via swift-evolution <swift-evolution at swift.org> wrote:
>>>> 
>>>>> On 2016-02-18, at 00:46, Kevin Ballard via swift-evolution <swift-evolution at swift.org> wrote:
>>>>> 
>>>>> Alternatively you can write
>>>>>  
>>>>>     subviews.lazy.flatMap({ $0 as? NSButton }).find({ $0.state == NSOnState })
>>>> 
>>>> Just to reiterate my point: I very much prefer the version without any casts. I just think this is much clearer and doesn’t put the burden of thinking about accidental memory and speed overhead (when forgetting the “lazy”) on the caller every time:
>>>> 
>>>> subviews.find(NSButton.self, matching: { $0.state == NSOnState })
>>>> 
>>>> Also, there’s the goal of Swift being easy to learn. Which line do you think is easier to explain to newcomers?
>>>> 
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution at swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>> 
>>> 
>>> 
>>> -- 
>>> Trent Nadeau
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> 
> 
> -- 
> Trent Nadeau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160218/688c04b7/attachment.html>


More information about the swift-evolution mailing list