[swift-evolution] [Review] SE-0187: Introduce Sequence.filterMap(_:)

BJ Homer bjhomer at gmail.com
Thu Nov 9 10:35:42 CST 2017


On Nov 9, 2017, at 9:13 AM, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> Experienced programmers (as experienced as any Swift programmer can be for a 4-year-old language) frequently use flatMap when they mean map
> When you look at those examples:
> What would stop those programmers to use filterMap in the exact same way, instead of switching to map?
> A hypothetic migrator most likely would just replace names…


The migrator would already have to be aware of the return type of the closure (to avoid migrating cases where it’s actually returning a sequence as expected), so the migrator could easily only migrate the ones that are actually returning optionals in the first place.

Programmers could continue to use filterMap incorrectly, but it would be a more explicit choice. Currently, there’s a sense among some Swift users (including some that I know personally) that flatMap is the “smart” thing to use with collections because monads or something, without any real understanding of why that is. (Remember, Swift doesn’t even have a “flatten()” function anymore, so the name “flatMap" is far from obvious.) I think it’s less likely that people will continue to use “filterMap” when they know no filtering is happening.

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


More information about the swift-evolution mailing list