| | |
| | | /// SwifterSwift: Sort the collection based on a keypath. |
| | | /// |
| | | /// - Parameter keyPath: Key path to sort by. The key path type must be Comparable. |
| | | mutating func sort<T: Comparable>(by keyPath: KeyPath<Element, T>) { |
| | | mutating func sort(by keyPath: KeyPath<Element, some Comparable>) { |
| | | sort { $0[keyPath: keyPath] < $1[keyPath: keyPath] } |
| | | } |
| | | |
| | |
| | | /// - Parameters: |
| | | /// - keyPath1: Key path to sort by. Must be Comparable. |
| | | /// - keyPath2: Key path to sort by in case the values of `keyPath1` match. Must be Comparable. |
| | | mutating func sort<T: Comparable, U: Comparable>(by keyPath1: KeyPath<Element, T>, |
| | | and keyPath2: KeyPath<Element, U>) { |
| | | mutating func sort(by keyPath1: KeyPath<Element, some Comparable>, |
| | | and keyPath2: KeyPath<Element, some Comparable>) { |
| | | sort { |
| | | if $0[keyPath: keyPath1] != $1[keyPath: keyPath1] { |
| | | return $0[keyPath: keyPath1] < $1[keyPath: keyPath1] |
| | |
| | | /// - keyPath1: Key path to sort by. Must be Comparable. |
| | | /// - keyPath2: Key path to sort by in case the values of `keyPath1` match. Must be Comparable. |
| | | /// - keyPath3: Key path to sort by in case the values of `keyPath1` and `keyPath2` match. Must be Comparable. |
| | | mutating func sort<T: Comparable, U: Comparable, V: Comparable>(by keyPath1: KeyPath<Element, T>, |
| | | and keyPath2: KeyPath<Element, U>, |
| | | and keyPath3: KeyPath<Element, V>) { |
| | | mutating func sort(by keyPath1: KeyPath<Element, some Comparable>, |
| | | and keyPath2: KeyPath<Element, some Comparable>, |
| | | and keyPath3: KeyPath<Element, some Comparable>) { |
| | | sort { |
| | | if $0[keyPath: keyPath1] != $1[keyPath: keyPath1] { |
| | | return $0[keyPath: keyPath1] < $1[keyPath: keyPath1] |