given the following playground fragment
let list = [4.2, 1.3, 7.8]
let list1 = list.sorted() { $0 < $1 }
let list2 = sorted(list)
let list3 = sorted(list) { $0 < $1}
I can use two forms of the free function sorted
, with or without the closure. But there is no such opportunity with the Array.sorted() method. Is there a good reason why not? Couldn't Apple have declared it as such?
func sorted(isOrderedBefore: (<T>, <t>) -> Bool = { $0 < $1 }) { ...
(As a side question, why does the playground show (3 times)
on the right side, instead of the resultant list for list1
and list3
?)