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

Max Moiseev moiseev at apple.com
Wed Nov 8 13:40:35 CST 2017



> On Nov 7, 2017, at 5:23 PM, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
> 
> -1
> 
> I guess breaking existing code will be the show stopper for this proposal — but I generally think that compatibility is a poor rationale to stop an improvement, so my personal reasons are different:
> The name is just wrong.
> Just have a look at this simple example
> 
> extension Int {
>     func justImagineError() throws -> Int {
>         return self
>     }
> }
> 
> let ints: [Int?] = [nil]
> 
> let result = ints.flatMap {
>     return try? $0?.justImagineError()
> }
> print(result)
> 
> If flatMap would really filter out nil values, this should yield an empty array as result — but the actual output is [nil]

This is a wonderful example! But it’s an argument for a different discussion (of general usefulness of implicit optional promotion). Thanks to the optional promotion, what the closure returns is not nil, but instead is .some(nil), and that is not filtered out.


> _______________________________________________
> 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/20171108/5ce600bf/attachment.html>


More information about the swift-evolution mailing list