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

Trent Nadeau tanadeau at gmail.com
Thu Feb 18 13:36:13 CST 2016


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
 })

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160218/ad542308/attachment.html>


More information about the swift-evolution mailing list