A closure passed on reducetakes 2 parameters, for example. $0and $1in abbreviated notation:
extension Array where Element: Equatable {
var removeDuplicate: [Element] {
return reduce([]) { $0.contains($1) ? $0 : $0 + [$1] }
}
}
(This compiles for both Swift 3 and 4).
Swift 3 $0, $0.0 $0.1.
Swift 4, SE-0110 .
, : This
let clo1: (Int, Int) -> Int = { (x, y) in x + y }
let clo2: ((Int, Int)) -> Int = { z in z.0 + z.1 }
Swift 3 4,
let clo3: (Int, Int) -> Int = { z in z.0 + z.1 }
Swift 3, Swift 4.