Skip to content

Instantly share code, notes, and snippets.

@loromits
Created December 13, 2017 14:00
Show Gist options
  • Save loromits/0f937de931f2d8e9fb6fa954730d4af7 to your computer and use it in GitHub Desktop.
Save loromits/0f937de931f2d8e9fb6fa954730d4af7 to your computer and use it in GitHub Desktop.
extension Dictionary {
func flatMapValues<T>(_ transform: (Value) throws -> T?) rethrows -> [Key: T] {
return try reduce(into: [:]) { $0[$1.key] = try transform($1.value) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment