> On May 25, 2016, at 4:31 PM, Erica Sadun <[email protected]> wrote:
> 
> 
>> On May 25, 2016, at 3:29 PM, Matthew Johnson <[email protected] 
>> <mailto:[email protected]>> wrote:
>> On May 25, 2016, at 3:56 PM, Erica Sadun <[email protected] 
>> <mailto:[email protected]>> wrote:
>>> I wouldn't be pushing if I thought it wouldn't be useful after cascading. 
>>> If no other reason, it offers a way to duplicate/modify value types to be 
>>> stored into constants. That alone should argue for its value.
>> 
>> Can you point us to the latest draft of what you have in mind for cascading 
>> in the future?  
> 
> Haven't really touched it since I got the "sit and wait" but I've come around 
> to preferring Dartism.

Got it.  I just looked up how Dart does this to refresh my memory.  

Are there cases where you think `with` would be a better option than method 
cascading other than the copy scenario?  

I think there are several ways we could handle the “copy and modify a value 
type” use case better than `with`.  The most obvious: if the primary reason for 
`with` to exist post-method cascading is to introduce a copy, I would prefer a 
`copy` function that could be used in conjunction with method cascading (which 
would then mutate and return the copy rather than the initial instance).

Brent’s example would go from:

        extension FloatingPoint {
                func adding(_ other: Self) -> Self {
                        return with(self) { $0.add(other) }
                }
        }

to: 

        extension FloatingPoint {
                func adding(_ other: Self) -> Self {
                        return copy(self)..add(other)
                }
        }

This reads much better than the former IMO.

I’m interested in hearing about use cases where `with` is superior to method 
cascading plus `copy`.  I think that is the minimum bar that should be crossed 
if we’re going to add this to the standard library.  

I’m not opposed to it on principle, but I want to make sure it carries its 
weight long term if we put it in the standard library.  It’s easy enough to 
copy into our projects if it’s not there and we feel the need to use it.


> 
> -- E
> 
> 

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to