Hello Swift evolution community!

Developing in Swift, I have many times found myself being frustrated that a 
function with default parameters can’t be passed to another function.

For example:

// sorts a string alphabetically
func sort(string: String, descending: Bool = false) -> String {
  return String(string.sorted { descending ? $1 < $0 : $0 < $1 })
}

let strings = [”swift", ”apple”, ”ios”]

If I wanted to map over the strings and sort each one, I would expect this to 
work:

strings.map(sort(string:)) // expected output: [”fistw", ”aelpp”, ”ios”]

However, this produces the error: use of unresolved identifier 'sort(string:)’

Instead, I have to write:

strings.map { sort(string: $0) }

Anybody else that would appreciate this possibility?
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to