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

BJ Homer bjhomer at gmail.com
Thu Nov 16 09:57:45 CST 2017


mapSome is easy to misunderstand; the naïve reading suggests that only some of the source elements will be mapped, and doesn’t specify which ones. Even if the reader correctly intuits that it refers to Optional.some, they may incorrectly believe that it only maps the non-nil elements in the source sequence. I don’t think this is the right solution.

mapAndUnwrap is accurate to the behavior, but gives an ambiguous impression of what will happen to the nil values. I would worry that returning nil would cause a crash due to a force-unwrap. I don’t want the nil values unwrapped; I want them dropped from the result entirely, so calling it “unwrap” feels scary.

I really think we need something that mentions that the purpose of using this operation is to drop empty values.

-BJ

> On Nov 16, 2017, at 8:40 AM, Shawn Erickson via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I so far am most in favor of mapSome out of the names I have seen followed by mapAndUnwrap (however the later is growing on me).
> 
> 
> To me the most important thing is when reading code that it is quick to understand generally what is going on followed by discoverability of a new comer. I think both of these are fairly clear on a quick read while a lot of the others are heavily overloaded terms. I also they sufficiently discoverable / learnable ... also mor so then some of the other overload terms.
> 
> -Shawn
> 
> 
> On Wed, Nov 15, 2017 at 10:07 PM Gwendal Roué via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> Le 16 nov. 2017 à 06:29, Matt Gallagher via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> a écrit :
>> 
>> My opinion is that filterMap is the right choice of name.
>> 
>> I'm completely biased, given that I already have a Swift library that uses filterMap, in exactly this context, for a Reactive Programming library:
>> 
>> 	https://github.com/mattgallagher/CwlSignal/blob/22f1d47895896d7b55bc59a4ee5394071f3c84cf/Sources/CwlSignal/CwlSignalReactive.swift#L453?ts=3 <https://github.com/mattgallagher/CwlSignal/blob/22f1d47895896d7b55bc59a4ee5394071f3c84cf/Sources/CwlSignal/CwlSignalReactive.swift#L453?ts=3>
> 
> 
> Another popular Reactive Programming Library uses filterMap with a different signature, and a different meaning: https://github.com/RxSwiftCommunity/RxSwiftExt/blob/3.0.0/Source/RxSwift/filterMap.swift#L32 <https://github.com/RxSwiftCommunity/RxSwiftExt/blob/3.0.0/Source/RxSwift/filterMap.swift#L32>
> 
> There are already different interpretations on "filter" in "filterMap" in the wild.
> 
> Gwendal Roué
> 
> _______________________________________________
> 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
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list