Map should have a method to retrieve a value but throws if the value is not present. #6640
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
core-2
library-collection
P2
A bug or feature request we're likely to work on
type-enhancement
A request for a change that isn't a bug
The current implementation of putIfAbsent in ImmutableMap is
V putIfAbsent(K key, V ifAbsent()) {
throw new UnsupportedError("Cannot set value in unmodifiable Map");
}
I'd prefer it if it actually called the ifAbsent function before that. My use case is that I have a method
externalObjectNamed(key) => externalObjects.putIfAbsent(key, () =>
throw 'Cannot find named object to link to: $key');
which is conveniently easy to write compared to doing an indexing operation and checking the result for null. But it cannot be used if the map is immutable.
The text was updated successfully, but these errors were encountered: