[swift-evolution] [Pitch] KeyPath based map, flatMap, filter

Brent Royal-Gordon brent at architechies.com
Thu Jul 6 01:00:00 CDT 2017

> On Jul 5, 2017, at 2:23 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> I am not convinced this syntactic sugar is worth complicating the
> language or library for,

For what it's worth, I think it is *totally* worth complicating the language or library. The manual alternative involves a ton of obfuscating code and punctuation:

	person.map { $0[keyPath: myKeyPath] }	// Don't tell me this isn't horrible.

> but if it is, IMO the right thing is to make a
> keypath be-a subtype of the appropriate function type, rather than to
> start down the path of creating a keypath overload for every method that
> takes a closure argument.

However, I think making `KeyPath<Foo, Bar>` a subtype of `(Foo) -> Bar` is a great way of handling this whole problem in one fell swoop—as long as it doesn't get delayed three or four versions while we clean up the type system.

Brent Royal-Gordon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170705/93429f2f/attachment.html>

More information about the swift-evolution mailing list