Skip to content

Instantly share code, notes, and snippets.

@michaeleisel
Created March 12, 2019 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeleisel/dd8e2e674af72f3c2fd18310fdbe3bdd to your computer and use it in GitHub Desktop.
Save michaeleisel/dd8e2e674af72f3c2fd18310fdbe3bdd to your computer and use it in GitHub Desktop.
extension Array {
func sortedWith<T: Comparable, U: Comparable>(_ comparableTransform: (Array.Element) -> (T, U)) -> [Array.Element] {
return sorted(by: { (a, b) -> Bool in
let tupleA = comparableTransform(a)
let tupleB = comparableTransform(b)
return tupleA.0 == tupleB.0 && tupleA.1 == tupleB.1
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment