[swift-evolution] [Accepted and Focused Re-review] SE-0187: Introduce Sequence.filterMap(_:)

BJ Homer bjhomer at gmail.com
Thu Nov 16 10:02:47 CST 2017


> On Nov 16, 2017, at 2:52 AM, Gwendal Roué via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> The optional itself will stand for the boolean needed by the filtering operation.
> 
> What I meant here is that "filterMap" can only click in a developer's mind if the the developer uses Optional as a Bool. When the closure returns nil, that nil stands for false in the filtering operation. When the closure returns a `some`, that some stands for true in the filtering operation.
> 
> Put in another way: to properly explain "filterMap" to someone who already knows "filter", then you have to explain that optionals are used as booleans.

I disagree that you have to view Optionals as Booleans to understand filterMap as proposed. Optionals naturally represent the idea of either a value, or nothing. The filterMap operation runs a map that can filter stuff out. If you filter something out, you end up with “nothing”, which is exactly what returning nil means. So when I use filterMap, I map all the things I want to let through, and I filter the rest out by letting nothing through.

-BJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171116/e6862e14/attachment.html>


More information about the swift-evolution mailing list