Skip to content

Instantly share code, notes, and snippets.

@kasperpeulen
Last active August 29, 2015 14:25
Show Gist options
  • Save kasperpeulen/7fbb9d27a05b7534a808 to your computer and use it in GitHub Desktop.
Save kasperpeulen/7fbb9d27a05b7534a808 to your computer and use it in GitHub Desktop.
How to remove a key/value pair, satisfying some test, from a `Map`.
void main() {
Map map = {
0: "not null",
1: null
};
bool test(key) => map[key] == null;
// This will remove all key/value pairs where the value is null.
map.keys.where(test).toList().forEach(map.remove);
// So the map should be of length 1 now.
assert(map.length == 1);
// prints {0: not null}
print(map);
}
name: dart.core_Map_Map.remove_'removeWhere'
description: |
How to remove a key/value pair, satisfying some test, from a `Map`.
Similar as the `List.removeWhere` method.
homepage: https://gist.github.com/kasperpeulen/7fbb9d27a05b7534a808
homepage: https://gist.github.com/kasperpeulen/7fbb9d27a05b7534a808
environment:
sdk: '>=1.0.0 <2.0.0'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment