> On Nov 16, 2017, at 2:52 AM, Gwendal Roué via swift-evolution 
> <swift-evolution@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
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to