Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "update" function to Map #16360

Open
lrhn opened this issue Jan 28, 2014 · 0 comments
Open

Add "update" function to Map #16360

lrhn opened this issue Jan 28, 2014 · 0 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-2 library-core type-enhancement A request for a change that isn't a bug

Comments

@lrhn
Copy link
Member

lrhn commented Jan 28, 2014

Add a method to Map that allows updating the value of an existing entry.
The operation should only do one lookup, but should otherwise work as:

V update(K key, V update(V value)) {
  this[key] = update(this[key]);
}

Optionally also allow to special case for non-existing elements:

V update(K key, V update(V value), {V ifAbsent()}) {
  V value = this[key];
  if (value == null && ifAbsent != null && !this.containsKey(key)) {
    this[key] = ifAbsent();
  } else {
    this[key] = update(value);
  }
}
@lrhn lrhn added Type-Enhancement library-core area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Jan 28, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Feb 29, 2016
@lrhn lrhn added the core-m label Aug 11, 2017
@floitschG floitschG added core-2 and removed core-m labels Aug 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-2 library-core type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants