Skip to content

Add support to Map interface to access entries as an Iterable and optionally to directly filter map entries #16117

@DartBot

Description

@DartBot

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.closed-duplicateClosed in favor of an existing reportlibrary-coretype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions