A type of Map
that maintains the order of iteration according to when entries were set.
type OrderedMap<K, V> extends Map<K, V>
The iteration behavior of OrderedMap is the same as native ES6 Map and JavaScript Object.
Note that OrderedMap
are more expensive than non-ordered Map and may consume more memory. OrderedMap#set is amortized O(log32 N)
, but not stable.
Let's look at the following example to see the difference between Map
and OrderedMap
:
The b
key is re-located on the second position.
The b
key is still on the third position.
Map
OrderedMap
has the exact same API as Map
. The only new method is OrderedMap.isOrderedMap(maybeOrderedMap)
to check if a value is an OrderedMap
.
Creates a new Immutable OrderedMap.
OrderedMap<K, V>(collection?: Iterable<[K, V]>): OrderedMap<K, V>
OrderedMap<V>(obj: { [key: PropertyKey]: V }): OrderedMap<PropertyKey, V>
Note: OrderedMap
is a factory function and not a class, and does not use the new
keyword during construction.
True if the provided value is an OrderedMap.
OrderedMap.isOrderedMap(maybeOrderedMap): boolean