Skip to content

Instantly share code, notes, and snippets.

@loromits
Last active February 1, 2018 13:43
Show Gist options
  • Save loromits/f2390028c54f1d7a06ec25003e61b0a4 to your computer and use it in GitHub Desktop.
Save loromits/f2390028c54f1d7a06ec25003e61b0a4 to your computer and use it in GitHub Desktop.
extension Sequence {
func toDictionary<T: Hashable>(_ keyTransformer: (Element) throws -> T) rethrows -> Dictionary<T, Element> {
return try reduce(into: [:]) { try $0[keyTransformer($1)] = $1 }
}
}
@loromits
Copy link
Author

loromits commented Feb 1, 2018

let assetsDictionary = assets.toDictionary { $0.name }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment