[swift-evolution] Request for Discussion: Setup closures

Kevin Ballard kevin at sb.org
Fri Dec 4 18:52:41 CST 2015

I'd be in favor of a solution like the '..' operator. Using a block-
based syntax for this seems like it's already close enough to defining
something like

func with<T>(x: T, @noescape _ f: inout T -> Void) -> T {    var value =
x    f(&value)    return value }

that it would be better to just go with the function instead of
complicating the Swift syntax. But the '..' operator has some nice
properties, such as being able to say something like

someLayoutConstraint =
label.leftAnchor.constraintEqualToAnchor(view.leftAnchor)..active = true

(I'm assuming here that '..' works by returning the receiver as the
value of the subsequent expression, rather than merely allowing several
'..' operators to be chained together, but I'm not actually familiar
with how this works in Smalltalk and Dart)

-Kevin Ballard

On Fri, Dec 4, 2015, at 01:27 PM, Joe Groff wrote:
> In Smalltalk and Dart, you can do this with method cascades, which
> apply multiple methods to the same 'self'. In Dart they use '..'
> for this:
> let task = NSTask()  ..launchPath = "..."  ..arguments = [...]
> ..standardOutput = pipe
> The nice thing about that is that it's a bit more generally applicable
> than just initialization.
> -Joe
> _________________________________________________
> swift-evolution mailing list swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151204/64b7101e/attachment.html>

More information about the swift-evolution mailing list