Skip to content

Instantly share code, notes, and snippets.

View s3cur3's full-sized avatar

Tyler A. Young s3cur3

View GitHub Profile
@s3cur3
s3cur3 / key-transform.swift
Last active March 20, 2021 12:13 — forked from christianselig/milkshake.swift
Generic versions of transforming Dictionary keys and values, inspired by https://twitter.com/ChristianSelig/status/1372961695346352130
extension Dictionary {
func mapKeys<NewKey>(_ transform: (Key) -> NewKey) -> [NewKey: Value] {
reduce(into: [NewKey: Value]()) { result, item in
result[transform(item.key)] = item.value
}
}
}
/// 🥤
extension Dictionary where Key: RawRepresentable {