[swift-evolution] Draft proposal: multi-property assignment .= operator

Jesse Rusak me at jesserusak.com
Mon Jan 11 08:16:45 CST 2016


> On Jan 11, 2016, at 8:40 AM, Michel Fortin via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> * If you continue with your draft, I suggest to explore this possibility further: With a function to turn members of an existing object into a tuple, or the option to selectively remove elements from a tuple, it could be a handy way to create copies.
> 
> I probably won't pursue it further since the general response was not much positive.

For what it’s worth, I think this is a good idea. I actually think that this is a nice stepping stone towards general solutions which help to reduce boilerplate, e.g. in initializers. For example, if you could refer to the arguments passed to the current function with some keyword (as in “arguments” in JS) then you could define relatively-concise and flexible initializers with something like:

struct Foo {
   let a: Int
   let b: String

   init(a: Int, b: String = “") {
      self .= $arguments
   }
}

In this case I think the “.=” would have to be a language feature in order to allow that assignment to statically satisfy the initialization requirements for a & b. 

- Jesse


More information about the swift-evolution mailing list