> I’m personally grateful that Swift reminds me that, for example, I need the 
> question mark in view.gestureRecognizers?.count. It would be maddening if 
> view.gestureRecognizers.count compiled, and always returned either 0 or 1. 
> Imagine it!
>     view.gestureRecognizers.count  // returns 0
>     view.gestureRecognizers = []
>     view.gestureRecognizers.count  // now returns 1 (wat?)
>     view.gestureRecognizers = [foo, bar, baz]
>     view.gestureRecognizers.count  // still returns 1 (wat?!)
> 
> That is a recipe for torches and pitchforks right there. Yet it is analogous 
> to what flatMap currently does.


[OT: NSView always returns an array here (which can be empty), and I think it 
is the right choice to avoid optional collections]

Even if the proposal is accepted, you still could do
v.gestureRecognizers.flatMap {
        print($0)
}
as well as
v.gestureRecognizers?.flatMap {
        print($0)
}

So we are not talking about fully abandoning the concept of a container with a 
flatMap-method, but rather break one part, and leave the other dangling around.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to