> Le 7 juin 2017 à 12:33, Gwendal Roué <gwendal.r...@gmail.com> a écrit : > > >> Le 7 juin 2017 à 12:03, Adrian Zubarev via swift-evolution >> <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> a écrit : >> >> Well please no: >> >> >> let fn2: ((Int, Int)) -> Void = { lhs, rhs in } >> >> Instead use destructuring sugar pitched by Chris Lattner on the other thread: >> >> let fn2: ((Int, Int)) -> Void = { ((lhs, rhs)) in } >> > > Despite Chris Lattern being a semi-god, his double-parenthesis suggestion > cruelly lacks in terms of user ergonomics. The compiler should be able to > deal with the following code snippet, just like Swift 3 does: > > // two arguments > func f1(_ closure: (Int, Int) -> Int) { closure(1, 2) } > [...]
Here is the full extent of the remarquable Swift 3 ergonomics. This full snippet compiles in Swift 3: func sum1(_ lhs: Int, _ rhs: Int) -> Int { return lhs + rhs } func sum2(lhs: Int, rhs: Int) -> Int { return lhs + rhs } func sum3(tuple: (Int, Int)) -> Int { return tuple.0 + tuple.1 } func sum4(tuple: (lhs: Int, rhs: Int)) -> Int { return tuple.lhs + tuple.rhs } // two arguments func f1(_ closure: (Int, Int) -> Int) { closure(1, 2) } f1 { lhs, rhs in lhs + rhs } f1 { (lhs, rhs) in lhs + rhs } f1 { tuple in tuple.0 + tuple.1 } f1 { (tuple) in tuple.0 + tuple.1 } f1(+) f1(sum1) f1(sum2) f1(sum3) f1(sum4) // two arguments, with documentation names: identical func f2(_ closure: (_ a: Int, _ b: Int) -> Int) { closure(1, 2) } f2 { lhs, rhs in lhs + rhs } f2 { (lhs, rhs) in lhs + rhs } f2 { tuple in tuple.0 + tuple.1 } f2 { (tuple) in tuple.0 + tuple.1 } f2(+) f2(sum1) f2(sum2) f2(sum3) f2(sum4) // one tuple argument func f3(_ closure: ((Int, Int)) -> Int) { closure((1, 2)) } f3 { lhs, rhs in lhs + rhs } f3 { (lhs, rhs) in lhs + rhs } f3 { tuple in tuple.0 + tuple.1 } f3 { (tuple) in tuple.0 + tuple.1 } f3(+) f3(sum1) f3(sum2) f3(sum3) f3(sum4) // one keyed tuple argument func f4(_ closure: ((a: Int, b: Int)) -> Int) { closure((a: 1, b: 2)) } f4 { lhs, rhs in lhs + rhs } f4 { (lhs, rhs) in lhs + rhs } f4 { tuple in tuple.a + tuple.b } f4 { (tuple) in tuple.a + tuple.b } f4(+) f4(sum1) f4(sum2) f4(sum3) f4(sum4) Gwendal
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution