[Discussion] Default Closure Arguments


(Andrew Bennett) #1

I'd like to be able to do this:

func callSomething(callback: (test: (arg: Int = 4) -> Void) -> Void) {

  callback(test: { print($0) })

}

callSomething { test in

  test()

}

Ideally the default argument would be part of the closure's type signature.

If-not then it could be part of callSomething's signature, and it could
lose the defaulted arguments if passed around.

What do you think?


(TJ Usiyan) #2

What would this help you express? It is fairly difficult to read the type
and understand your motivation from this reduced example. It is clear what
you want but not what it wins you or us.

···

On Tue, Jun 14, 2016 at 3:40 AM, Andrew Bennett via swift-evolution < swift-evolution@swift.org> wrote:

I'd like to be able to do this:

func callSomething(callback: (test: (arg: Int = 4) -> Void) -> Void) {

  callback(test: { print($0) })

}

callSomething { test in

  test()

}

Ideally the default argument would be part of the closure's type signature.

If-not then it could be part of callSomething's signature, and it could
lose the defaulted arguments if passed around.

What do you think?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution