Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-10 Thread David Hart via swift-evolution
> On 9 Jun 2017, at 19:06, Max Moiseev via swift-evolution > wrote: > > Sorry. I might be missing something. Why is this better than: > > let allEmployees = Set(managers.flatMap { $0.directReports } > > ? For the same reasons

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-09 Thread Dave Abrahams via swift-evolution
on Fri Jun 09 2017, Saagar Jha wrote: > It reads better and feels more natural. In my mind, it’s similar to the > difference between > > ["1", "2", "3"].flatMap { Double($0) } > > and > > ["1", "2", "3"].flatMap(Double.init) > > Saagar Jha I am not convinced this

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-09 Thread Saagar Jha via swift-evolution
It reads better and feels more natural. In my mind, it’s similar to the difference between ["1", "2", "3"].flatMap { Double($0) } and ["1", "2", "3"].flatMap(Double.init) Saagar Jha > On Jun 9, 2017, at 16:06, Max Moiseev via swift-evolution > wrote: > > Sorry.

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-09 Thread Karl Wagner via swift-evolution
> On 7. Jun 2017, at 19:35, Adam Sharp via swift-evolution > wrote: > > The new smart key path feature is really lovely, and feels like a great > addition to Swift. > > It seems like it might be straightforward to add overloads of `map` and > `flatMap` to the

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-09 Thread Karl Wagner via swift-evolution
> On 10. Jun 2017, at 01:42, Karl Wagner wrote: > >> >> On 8. Jun 2017, at 04:58, Tony Allevato via swift-evolution >> > wrote: >> >> +1, I really like this. It would also align nicely with the method type >>

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-09 Thread Karl Wagner via swift-evolution
> On 8. Jun 2017, at 04:58, Tony Allevato via swift-evolution > wrote: > > +1, I really like this. It would also align nicely with the method type > flattening in SE-0042 >

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-09 Thread Max Moiseev via swift-evolution
Sorry. I might be missing something. Why is this better than: let allEmployees = Set(managers.flatMap { $0.directReports } ? > On Jun 7, 2017, at 10:35 AM, Adam Sharp via swift-evolution > wrote: > > The new smart key path feature is really lovely, and feels like a

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-08 Thread Matt Diephouse via swift-evolution
 > On Jun 7, 2017, at 10:35 AM, Adam Sharp via swift-evolution > wrote: > > The new smart key path feature is really lovely, and feels like a great > addition to Swift. > > It seems like it might be straightforward to add overloads of `map` and > `flatMap` to the

[swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-08 Thread tobias--- via swift-evolution
I had the need for the same thing today and made it as an extension on Sequence. extension Sequence { func map(_ keyPath: KeyPath) -> [T] { return self.map { $0[keyPath: keyPath] } } func flatMap(_ keyPath: KeyPath) -> [T] {

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-08 Thread Paul Cantrell via swift-evolution
Ah, quite ingenious, Susan! And you made me realize that the only reason my no-operator-needed code didn’t compile is that I had keypath instead of keyPath. So it was indeed “Paul needs to go to sleep now” option, which I will now do.  P > On Jun 7, 2017, at 11:34 PM, Susan Cheng

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-07 Thread Stephen Celis via swift-evolution
:D Great example for what I was trying to say. We can compose such a thing with existing code and not require an overload per. > On Jun 8, 2017, at 12:34 AM, Susan Cheng wrote: > > this work, > > prefix operator * > > prefix func *(keyPath: KeyPath

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-07 Thread Susan Cheng via swift-evolution
this work, prefix operator * prefix func *(keyPath: KeyPath) -> (Root) -> Value { return { $0[keyPath: keyPath] } } ["Hello, World"].map(*\String.count)// [12] 2017-06-08 12:19 GMT+08:00 Paul Cantrell via swift-evolution < swift-evolution@swift.org>: >

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-07 Thread Paul Cantrell via swift-evolution
It should be possible to achieve Ruby-like generality in Swift with a protocol for “thing that can converted to a transform function.” That wouldn’t need a special & operator. Here’s a sketch. This sketch doesn’t compile — maybe not enough of Swift 4 is there yet for it to work, or maybe I am

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-07 Thread Stephen Celis via swift-evolution
-1 A -1 from me may be surprising. I'm excited about key path composition and generic solutions, e.g. this experiment with lenses: https://twitter.com/stephencelis/status/863916921577758721 But I'd prefer a reusable solution for converting key paths into functions. Heaven help me for this

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-07 Thread Tony Allevato via swift-evolution
+1, I really like this. It would also align nicely with the method type flattening in SE-0042 (once it gets implemented), because passing keypaths (i.e., unbound property references) and unbound

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-07 Thread Xiaodi Wu via swift-evolution
+1. Would think that all variants should exist on Optional too unless it would be harmful. On Wed, Jun 7, 2017 at 20:13 Michael J LeHew Jr via swift-evolution < swift-evolution@swift.org> wrote: > This is a great idea, and ought to be easy enough to bring forward! +1 > from me! > > -Michael > >

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-07 Thread Michael J LeHew Jr via swift-evolution
This is a great idea, and ought to be easy enough to bring forward! +1 from me! -Michael > On Jun 7, 2017, at 11:18 AM, Matt Diephouse via swift-evolution > wrote: > >  > >> On Jun 7, 2017, at 10:35 AM, Adam Sharp via swift-evolution >>

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-07 Thread Matt Diephouse via swift-evolution
 > On Jun 7, 2017, at 10:35 AM, Adam Sharp via swift-evolution > wrote: > > The new smart key path feature is really lovely, and feels like a great > addition to Swift. > > It seems like it might be straightforward to add overloads of `map` and > `flatMap` to the

Re: [swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-07 Thread Víctor Pimentel Rodríguez via swift-evolution
On Wed, Jun 7, 2017 at 7:35 PM, Adam Sharp via swift-evolution < swift-evolution@swift.org> wrote: > The new smart key path feature is really lovely, and feels like a great > addition to Swift. > > It seems like it might be straightforward to add overloads of `map` and > `flatMap` to the standard

[swift-evolution] Pitch: Support for map and flatMap with smart key paths

2017-06-07 Thread Adam Sharp via swift-evolution
The new smart key path feature is really lovely, and feels like a great addition to Swift. It seems like it might be straightforward to add overloads of `map` and `flatMap` to the standard library to make use of the new functionality: let managers = flatOrganisation.managers