kotlinx.collections.immutable icon indicating copy to clipboard operation
kotlinx.collections.immutable copied to clipboard

Add getOrPut equivilant to PersistentMap

Open rnett opened this issue 9 months ago • 0 comments

getOrPut is a commonly used function on mutable maps. I would like to have a function to fill the same niche on PersistentMap - creating and adding the new value only if the existing value is not present. This can be done using a contains check and then a put, but that requires two scans of the map, while this method should only require one.

In particular, I'd like it if the method:

  • inlined the lambda
  • Returned both the new map, and the updated value for the key

rnett avatar Jun 27 '25 01:06 rnett