Created
May 6, 2017 00:46
-
-
Save DJBen/8f60b251ff3223a7e4fd4595b39b2d66 to your computer and use it in GitHub Desktop.
Swift 3 map function ordered by key
This file contains hidden or 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 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