Skip to content

Conversation

@tayloraswift
Copy link
Member

Efficient Dictionary.mapValues with key context

I propose adding an overload to Dictionary.mapValues (and OrderedDictionary.mapValues) that passes the Key to the transformation closure.

This enables us to transform dictionary values with their associated key context without incurring the performance cost of rehashing (or in the case of reduce, reallocating) the dictionary storage, which is currently unavoidable when using init(uniqueKeysWithValues:) or reduce(into:).

@tayloraswift tayloraswift marked this pull request as ready for review January 2, 2026 21:15
@rjmccall rjmccall added LSG Contains topics under the domain of the Language Steering Group new proposal Adds a new proposal document labels Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LSG Contains topics under the domain of the Language Steering Group new proposal Adds a new proposal document

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants