Extension methods for Maps

Static methods

staticcopyTo<TKey, TValue> (src:IMap<TKey, TValue>, dst:IMap<TKey, TValue>):IMap<TKey, TValue>

Copies all the key/values pairs from src to dst. It overwrites already existing keys in dst if needed.

staticfoldLeftWithKeys<K, A, B> (map:Map<K, A>, f:B ‑> K ‑> A ‑> B, acc:B):B

Unordered fold over key/value pairs in the map.

staticfromArray<T, K, V> (array:ReadonlyArray<T>, toKey:T ‑> K, toVal:T ‑> V):Map<K, V>

Creates a Map<K, V> from an Array<T> using key extractor T -> K and value extractor T -> V functions. K must be a string.

staticgetAlt<TKey, TValue> (map:Map<TKey, TValue>, key:TKey, alt:TValue):TValue

Given a key returns the associated value from map. If the key doesn't exist or the associated value is null, it returns the provided alt value instead.

staticgetAltSet<TKey, TValue> (map:Map<TKey, TValue>, key:TKey, alt:TValue):TValue

Given a key returns the associated value from map. If the key doesn't exist or the associated value is null, it returns the provided alt value instead, and stores the alt value in the map.

staticgetOption<TKey, TValue> (map:IMap<TKey, TValue>, key:TKey):Option<TValue>

Null-safe get.

staticinline isEmpty<TKey, TValue> (map:Map<TKey, TValue>):Bool

Returns true if the map is empty (no key/value pairs).

staticinline isMap (v:Dynamic):Bool

Returns true if a value is of any type of Map. Equivalent to Std.is(v, IMap).

staticmapValues<TKey, TValueA, TValueB> (map:IMap<TKey, TValueA>, f:TValueA ‑> TValueB, acc:Map<TKey, TValueB>):Map<TKey, TValueB>

It maps values from one Map instance to another.

staticmerge<TKey, TValue> (dest:IMap<TKey, TValue>, sources:Array<IMap<TKey, TValue>>):IMap<TKey, TValue>

Merges 0 or more maps of the same type into a destination map. Successive source maps will overwrite values for the same key from previous sources. The destination map is modified in place, and the destination is also returned from the function. To merge into an empty map, pass a new empty map as the dest argument.

var result1 = map1.merge([map2, map3]); // result1 and map1 should be the same after this.  map2 and map3 are not modified.
var result2 = (new Map() : Map<String, Int>).merge(map1, map2); // map1 and map2 not modified

staticreduce<TKey, TValue, TOut> (map:IMap<TKey, TValue>, f:TOut ‑> Tuple<TKey, TValue> ‑> TOut, acc:TOut):TOut

Applies the reduce function on every key/value pair in the map.

staticsemigroup<K, V> ():Semigroup<IMap<K, V>>

The way that Haxe specializes maps inhibits us from defining a Monoid instance for maps. The recommended way to reduce an array of maps is Nel.nel(new Map(), maps).fold(Maps.semigroup())

staticstring<TKey, TValue> (m:IMap<TKey, TValue>):String

statictoObject<T> (map:Map<String, T>):{}

mapToObject transforms a Map<String, T> into an anonymous object.

statictuples<TKey, TValue> (map:IMap<TKey, TValue>):Array<Tuple2<TKey, TValue>>

Converts a Map into an Array>

staticvalues<TKey, TValue> (map:IMap<TKey, TValue>):Array<TValue>

Extracts the values of a Map into Array