Skip to content

Instantly share code, notes, and snippets.

@michaeleisel
Created March 6, 2019 22:08
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/88fb4808ab4867169385e7f01830d3ad to your computer and use it in GitHub Desktop.
Save michaeleisel/88fb4808ab4867169385e7f01830d3ad to your computer and use it in GitHub Desktop.
extension Array {
func sortedWith<T: Comparable>(_ comparableTransform: (Array.Element) -> T) -> [Array.Element] {
return sorted(by: { (a, b) -> Bool in
return comparableTransform(a) > comparableTransform(b)
})
}
}
let carts: [Card] = []
carts = carts.sortedWith({ (cart) -> (Int, Int) in // generic parameter error here
let c: (Int, Int) = (cart.rowIndex, cart.columnIndex)
return c
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment