the key type
the value type
The empty map.
the key type
the value type
Curried predicate to find out whether the HashMap is empty.
Vector.of(HashMap.of([1,2]), HashMap.empty<number,number>())
.filter(HashMap.isEmpty)
=> Vector.of(HashMap.empty<number,number>())
Curried predicate to find out whether the HashMap is empty.
Vector.of(HashMap.of([1,2]), HashMap.empty<number,number>())
.filter(HashMap.isNotEmpty)
=> Vector.of(HashMap.of([1,2]))
Build a HashMap from key-value pairs.
HashMap.of([1,"a"],[2,"b"])
Build a HashMap from an iterable containing key-value pairs.
HashMap.ofIterable(Vector.of<[number,string]>([1,"a"],[2,"b"]));
Build a HashMap from a javascript object literal representing a dictionary. Note that the key type must always be string, as that's the way it works in javascript. Also note that entries with undefined values will be stripped from the map.
HashMap.ofObjectDictionary<number>({a:1,b:2})
=> HashMap.of(["a",1],["b",2])
Implementation of the Iterator interface.
Returns true if the predicate returns true for all the elements in the collection.
Returns true if there the predicate returns true for any element in the collection.
Returns true if the item is in the collection, false otherwise.
Returns true if there is item with that key in the collection, false otherwise.
HashMap.of<number,string>([1,"a"],[2,"b"]).containsKey(1);
=> true
HashMap.of<number,string>([1,"a"],[2,"b"]).containsKey(3);
=> false
Two objects are equal if they represent the same value, regardless of whether they are the same object physically in memory.
Call a predicate for each element in the collection, build a new collection holding only the elements for which the predicate returned true.
Call a predicate for each key in the collection, build a new collection holding only the elements for which the predicate returned true.
HashMap.of<number,string>([1,"a"],[2,"b"]).filterKeys(k=>k%2===0)
=> HashMap.of<number,string>([2,"b"])
Call a predicate for each value in the collection, build a new collection holding only the elements for which the predicate returned true.
HashMap.of<number,string>([1,"a"],[2,"ab"]).filterValues(v=>v.length>1)
=> HashMap.of<number,string>([2,"ab"])
Search for an item matching the predicate you pass, return Option.Some of that element if found, Option.None otherwise. We name the method findAny instead of find to emphasize that there is not ordering in a hashset.
HashMap.of<number,string>([1,'a'],[2,'b'],[3,'c'])
.findAny((k,v) => k>=2 && v === "c")
=> Option.of([3,'c'])
HashMap.of<number,string>([1,'a'],[2,'b'],[3,'c'])
.findAny((k,v) => k>=3 && v === "b")
=> Option.none<[number,string]>()
Calls the function you give for each item in the map, your function returns a map, all the maps are merged.
Reduces the collection to a single value using the associative binary function you give. Since the function is associative, order of application doesn't matter.
Example:
HashMap.of<number,string>([1,"a"],[2,"b"],[3,"c"])
.fold([0,""], ([a,b],[c,d])=>[a+c, b>d?b:d])
=> [6,"c"]
Reduces the collection to a single value. Left-associative. No guarantees for the order of items in a hashset!
Example:
HashMap.of([1,"a"], [2,"bb"], [3,"ccc"])
.foldLeft(0, (soFar,[item,val])=>soFar+val.length);
=> 6
The initial value
A function taking the previous value and the current collection item, and returning an updated value.
Reduces the collection to a single value. Right-associative. No guarantees for the order of items in a hashset!
Example:
HashMap.of([1,"a"], [2,"bb"], [3,"ccc"])
.foldRight(0, ([item,value],soFar)=>soFar+value.length);
=> 6
The initial value
A function taking the current collection item and the previous value , and returning an updated value.
Call a function for element in the collection.
Get the value for the key you give, if the key is present.
Get a number for that object. Two different values may get the same number, but one value must always get the same number. The formula can impact performance.
true if the map is empty, false otherwise.
Get a Set containing all the keys in the map
number of items in the map
Return a new map where each entry was transformed by the mapper function you give. You return key,value as pairs.
Return a new map where keys are the same as in this one, but values are transformed by the mapper function you give. You return key,value as pairs.
Create a new map combining the entries of this map, and the other map you give. In case an entry from this map and the other map have the same key, the merge function will be invoked to get a combined value.
It is guaranteed that the merge function first parameter will be the entry from this map, and the second parameter from the map you give.
a merge function to combine two values in case two entries share the same key.
Add a new entry in the map. If there was entry with the same key, it will be overwritten.
the key
the value
Add a new entry in the map; in case there was already an entry with the same key, the merge function will be invoked with the old and the new value to produce the value to take into account.
It is guaranteed that the merge function first parameter will be the entry from this map, and the second parameter from the map you give.
the key
the value
a function to merge old and new values in case of conflict.
Reduces the collection to a single value by repeatedly calling the combine function. No starting value. The order in which the elements are passed to the combining function is undetermined.
Return a new map with the key you give removed.
If the collection contains a single element, return Some of its value, otherwise return None.
Convert to array.
Convert to an ES6 Map. You must provide a function to convert the key to a string, number or boolean, because with other types equality is not correctly managed by JS. https://stackoverflow.com/questions/29759480/how-to-customize-object-equality-for-javascript-set https://esdiscuss.org/topic/maps-with-object-keys
HashMap.of<string,number>(["a",1],["b",2])
.toJsMap(x=>x);
=> new Map([["a",1], ["b",2]])
Convert this map to a list of key,value pairs. Note that Map is already an iterable of key,value pairs!
Convert to a javascript object dictionary You must provide a function to convert the key to a string.
HashMap.of<string,number>(["a",1],["b",2])
.toObjectDictionary(x=>x);
=> {a:1,b:2}
Convert this map to a vector of key,value pairs. Note that Map is already an iterable of key,value pairs!
Transform this value to another value type. Enables fluent-style programming by chaining calls.
Get an iterable containing all the values in the map (can't return a set as we don't constrain map values to have equality in the generics type)
Generated using TypeDoc
A dictionary, mapping keys to values.