ListMap<K, V>.unsafeFrom constructor

ListMap<K, V>.unsafeFrom({
  1. required Map<K, V> map,
  2. required List<K> list,
})

Creates a ListMap backed by the provided map and list. No defensive copies will be made, so you have to make sure that:

  1. The number of entries of the map and list won't change after the ListMap is created.

  2. The map and list won't change after the ListMap is created.

  3. The list items are the map keys (but the order of the map items is irrelevant).

Implementation

ListMap.unsafeFrom({
  required Map<K, V> map,
  required List<K> list,
})  : _map = map,
      _list = list {
  if (map.length != list.length)
    throw AssertionError('Map has ${map.length} but list has ${list.length} items.');
}