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

David Waite david at alkaline-solutions.com
Thu Feb 18 15:23:35 CST 2016


A version specifically for dealing with downcasts seems very special purpose to this particular use case, especially when you can just use flatMap.

-DW

> On Feb 18, 2016, at 2:01 PM, Thorsten Seitz via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> Am 18.02.2016 um 20:36 schrieb Trent Nadeau via swift-evolution <swift-evolution at swift.org <mailto: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 <mailto:swift-evolution at swift.org>> wrote:
>> 
>>> On 2016-02-18, at 00:46, Kevin Ballard via swift-evolution <swift-evolution at swift.org <mailto: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 <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>> 
>> 
>> 
>> 
>> --
>> Trent Nadeau
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160218/0ac950f2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160218/0ac950f2/attachment.sig>


More information about the swift-evolution mailing list