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

Erica Sadun erica at ericasadun.com
Tue Dec 20 12:59:51 CST 2016


Cascading falls under a separate proposal. There's an intermediate form which stagnated here: https://gist.github.com/erica/6794d48d917e2084d6ed <https://gist.github.com/erica/6794d48d917e2084d6ed>

As Xiaodi Wu pointed out, you can introduce an implementation of `with` that uses reflection but that would be deferred to a later date when reflection itself gets updated.

-- E


> On Dec 20, 2016, at 7:44 AM, Martin Waitz <tali at admingilde.org> wrote:
> 
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161220/492a10c8/attachment.html>


More information about the swift-evolution mailing list