Skip to content

Instantly share code, notes, and snippets.

extension Dictionary {
/// Transforms dictionary keys without modifying values.
/// Deduplicates transformed keys.
///
/// Example:
/// ```
/// ["one": 1, "two": 2, "three": 3, "": 4].mapKeys({ $0.first }, uniquingKeysWith: { max($0, $1) })
/// // [Optional("o"): 1, Optional("t"): 3, nil: 4]
/// ```