Last active
March 20, 2021 11:37
-
-
Save christianselig/ea4a3e8a7816bfff6a10668b59f2d629 to your computer and use it in GitHub Desktop.
A beautiful milkshake where the ingredients are Sean Heber, Yakov Shapovalov, and Hunter Meyer.
This file contains 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: RawRepresentable { | |
func rawConversion<NewKey>() -> Dictionary<NewKey, Value> where NewKey == Key.RawValue { | |
let newDict: [NewKey: Value] = self.reduce(into: [:]) { (result, item) in | |
result[item.key.rawValue] = item.value | |
} | |
return newDict | |
} | |
} |
To allow for type inferencing,
func rawConversion<NewKey>(to type: NewKey.Type) -> Dictionary<NewKey, Value> where NewKey == Key.RawValue
with the call site:
checklist2 = checklist1.rawConversion(to: String.self)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can make it an (almost) one-liner like this: