I just today realized that Immutable.js doesn't provide an operation for this, though I really only need it for SortedMap. I would like a method on SortedMap that removes and returns the value under the given key as well as the updated map. In Flow the function prototype is straightforward:
getAndDelete(key: K): [?V, SortedMap<K, V>] {}
let [val, map] = map.getAndDelete('key');
Apparently in Immutable.js this can be done by returning null from the closure passed to Collection.update() (though this is undocumented) but SortedMap doesn't appear to support this; it just updates the value as null. I know this can be done with get() then delete() but I'd like to avoid the redundant lookup if possible.
I just today realized that Immutable.js doesn't provide an operation for this, though I really only need it for
SortedMap. I would like a method onSortedMapthat removes and returns the value under the given key as well as the updated map. In Flow the function prototype is straightforward:Apparently in Immutable.js this can be done by returning
nullfrom the closure passed toCollection.update()(though this is undocumented) butSortedMapdoesn't appear to support this; it just updates the value asnull. I know this can be done withget()thendelete()but I'd like to avoid the redundant lookup if possible.