Skip to content

Instantly share code, notes, and snippets.

@DJBen
Created May 6, 2017 00:46
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 DJBen/8f60b251ff3223a7e4fd4595b39b2d66 to your computer and use it in GitHub Desktop.
Save DJBen/8f60b251ff3223a7e4fd4595b39b2d66 to your computer and use it in GitHub Desktop.
Swift 3 map function ordered by key
extension Dictionary where Key: Comparable {
func keyOrderMap<T>(_ transform: @escaping ((key: Key, value: Value)) throws -> T) rethrows -> [T] {
return try keys.sorted().map { try transform(($0, self[$0]!)) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment