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

Marco Masser lists at duckcode.com
Thu Feb 18 03:37:11 CST 2016


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


More information about the swift-evolution mailing list