> On Nov 8, 2017, at 9:29 PM, Paul Cantrell via swift-evolution
> <[email protected]> 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
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution