本页尚未翻译,因此以英文显示。 参与翻译

keys

The keys of a Map, as a plain lazy Iterable — ready to wrap in fx() and chain.

Iterable<K> keys<K, V>(Map<K, V> map)

Lecture

keys(map) is a thin, FxTS-flavored wrapper around Dart's own map.keys — it exists mainly so the object-function vocabulary (entries, keys, values) reads consistently and slots straight into fx(). Dart's Map.keys is already a lazy view, so keys doesn't add any extra buffering — it just hands you the same lazy Iterable<K>.

Reach for it when you want to filter, transform, or collect a Map's key set using the rest of the chain vocabulary, rather than reaching for .where()/.toList() on map.keys directly — the two are equivalent, but fx(keys(map)) reads naturally next to fx(values(map)) and fx(entries(map)).

If you need the keys and values together, use entries instead — pulling keys and values separately does not guarantee they line up if the underlying map were mutated between the two calls.

Demo 1 · Basics

Demo 2 · Filtering a Map by its keys

Try it yourself

Exercise: use keys and sort to get an alphabetically sorted list of item names.

Related: entries — keys and values paired together · values — the values of a Map · pick — build a new Map from a subset of keys · fx — the chain keys results feed into