“contextual closure type expects 2 arguments” error when using reduce in Swift 4
问题 The following code compiles in Swift 3 extension Array where Element: Equatable { var removeDuplicate: [Element] { return reduce([]){ $0.0.contains($0.1) ? $0.0 : $0.0 + [$0.1] } } } but produces the error error: contextual closure type '(_, _) -> _' expects 2 arguments, but 1 was used in closure body in Swift 4. How to convert this code to be compiled in Swift 4? 回答1: The closure passed to reduce takes 2 parameters, e.g. $0 and $1 in the shorthand notation: extension Array where Element: