Esta página ainda não foi traduzida, por isso é exibida em inglês. Ajude a traduzir

fromEntries

Builds a Map from an iterable of (key, value) records.

Map<K, V> fromEntries<K, V>(Iterable<(K, V)> entries)

Lecture

This section ports FxTS's object utilities, and the first thing to understand is the mapping: TypeScript's plain objects become Dart Maps throughout, and TS's [key, value] entry tuples become Dart (K, V) records. fromEntries is the constructor side of that: give it any iterable of records and it folds them into a Map, last-write-wins on duplicate keys — exactly like building the map by hand with a loop.

It's the natural partner of entries (which does the reverse: Map → records) and pairs nicely with zip, which turns two parallel lists into exactly the record shape fromEntries wants.

Demo 1 · Basics

Demo 2 · Duplicate keys, and round-tripping with entries

Try it yourself

Exercise: use fromEntries to turn pairs into a Map.

Related: entries — the reverse direction · zip — build entries from two parallel lists · omit — drop keys from the resulting Map · pick — keep only some keys