[swift-evolution] [Review] SE-0187: Introduce Sequence.filterMap(_:)
Brent Royal-Gordon
brent at architechies.com
Sun Nov 12 21:35:07 CST 2017
> On Nov 8, 2017, at 9:29 PM, Paul Cantrell via swift-evolution <swift-evolution at swift.org> wrote:
>
> The problem in the Doodads example is that the name flatMap is used to identify two distinct intents: concatenating arrays and filtering nils. One can argue that those two operations are, in some lofty abstract sense, if you squint, two instances of some more general pattern — but I don’t think it’s fair to say that they represent the same intent. These separate intents deserve separate names.
I think that's the crux of it.
I think we might be better off renaming the maps on `Optional` and then naming the `Sequence` operation analogously. For instance:
Optional.map(transform) => Optional.pass(to: transform)
Optional.flatMap(transform) => Optional.chain(to: transform)
Then this would be a natural choice:
Sequence.flatMap(transform) => Sequence.chainMap(transform)
Alternatively, we could think of a name for "removing optionality from a sequence" and then use that name. For example, borrowing a name from Ruby:
(Sequence where Element == T?).compact()
Sequence.compactMap(transform)
Actually, "unwrapped" might be a better name than "compact", since we use that term.
--
Brent Royal-Gordon
Architechies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171112/8a5b66f9/attachment.html>
More information about the swift-evolution
mailing list