-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
This issue was originally filed by @Andersmholmgren
i.e. something like
Iterable<KeyValuePair<K, V>> get entries;
It's often useful to be able to iterate of the entry set of a map and process entry by entry. This is common in other languages like Java.
e.g you could do stuff like
final Map<Symbol, MethodMirror> instanceMembers = reflect(o).type.instanceMembers;
final Iterator<KeyValuePair<Symbol, MethodMirror>> getters = instanceMembers.entries.where((kv) =>
kv.value.isGetter);
final Iterable<KeyValuePair<Symbol, Object>> getterValues = getters.map((kv) =>
new KeyValuePair(kv.key, invokeGetter(kv.value)));
Sadly in this example I ended up into https://code.google.com/p/dart/issues/detail?id=10975 so it proved futile but this sort of thing is very useful
Also (but less important) it can be useful to filter a map directly.
i.e.
Map<K,V> where(bool test(K key, V value));
This allows you then to create a subset of the first map and work on that.