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

Tino Heth 2th at gmx.de
Fri Nov 10 05:31:00 CST 2017


> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171110/8a59641c/attachment.html>


More information about the swift-evolution mailing list