I've been using compactMapValues() to transform values in a dictionary, resulting in a new dictionary. But it turns out I need the key as well. After some searching I found the (cryptic) solution: Dictionary.reduce(into:).
This lets one build a new dictionary from an existing dictionary with full access to the source key/value pair.
Here's my reference:
https://medium.com/@mihirr_panchaal/swift-dictionary-reduce-into-5e59de99eeba