Created
September 11, 2022 16:03
-
-
Save florianpircher/a69fa36cf335ddc4c6cfb07ad204bc8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Sequence { | |
func sorted<SortKey>( | |
by areInIncreasingOrder: (SortKey, SortKey) throws -> Bool, | |
sortKey makeSortKey: (Element) throws -> SortKey | |
) rethrows -> [Element] { | |
try self | |
.map { (key: try makeSortKey($0), element: $0) } | |
.sorted { try areInIncreasingOrder($0.key, $1.key) } | |
.map { $0.element } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment