[swift-evolution] "with" operator a la O'Caml?

Martin Waitz tali at admingilde.org
Tue Dec 20 08:44:39 CST 2016


Am 2016-12-19 20:44, schrieb Erica Sadun via swift-evolution:
> https://github.com/apple/swift-evolution/pull/346

-1
I don't like where this is heading.

If you want to introduce method cascading, then have a look at Dart.

E.g. the example from the pull request could be something like this:

     let questionLabel = UILabel()
         ..textAlignment = .Center
         ..font = UIFont(name: "DnealianManuscript", size: 72)
         ..text = questionText

The expression could still work on a mutable struct/class which later 
becomes
immutable by using the `let` assignment.

The other example which silently creates a new instance is even worse.
If you want to do something like this, then please do it more 
explicitly.
E.g.:

     let fewerFoos = foos.clone()
         ..remove(at: i)

Anyway, all of this is simply syntactic sugar and should wait...

-- 
Martin


More information about the swift-evolution mailing list