novah.map
Functions to work with persistent maps.
Types
Declarations
new
visibility: public
type: List (Tuple k v) -> Map k v
Creates a new map with the supplied entries.
newEq
visibility: public
type: {{ Equals k }} -> Option (k -> Int64) -> Map k v
Creates a new map which uses the key equality function and the provided hash function, or the default object hash function.
This function should always be used to create new maps for types that have equality implementations that differ from its own
equals
function.
Note that Novah creates default, sensible equals
and hashCode
implementations for every type.
size
visibility: public
type: Map k v -> Int64
Returns the size of the map. Runtime: O(1)
isEmpty
visibility: public
type: Map k v -> Boolean
Return true if the map is empty Runtime: O(1)
isNotEmpty
visibility: public
type: Map k v -> Boolean
Return true if the map is not empty Runtime: O(1)
put
visibility: public
type: k -> v -> Map k v -> Map k v
Inserts or replaces a new key/value pair in the map. Runtime: ~O(1)
get
visibility: public
type: k -> Map k v -> Option v
Returns the value under key if it exists. Runtime: ~O(1)
getOr
visibility: public
type: k -> v -> Map k v -> v
Returns the value under key if it exists, or the default value. Runtime: ~O(1)
update
visibility: public
type: k -> (v -> v) -> Map k v -> Map k v
Applies the function to the value represented by the key, updating it. Does nothing if the key is not present. Runtime: ~O(1)
updateOr
visibility: public
type: k -> (v -> v) -> v -> Map k v -> Map k v
Applies the function to the value represented by the key, updating it. Inserts the or value if the key is not present. Runtime: ~O(1)
remove
visibility: public
type: k -> Map k v -> Map k v
Removes the key from this map. Runtime: ~O(1)
hasKey
visibility: public
type: k -> Map k v -> Boolean
Returns true if this map contains the key. Runtime: ~O(1)
merge
visibility: public
type: Map k v -> Map k v -> Map k v
Returns the result of merging the two maps.
Repeated keys in the second map will overwrite keys from the first.
An alias for ++
.
keys
visibility: public
type: Map k v -> Set k
Returns a set of all keys in this map. Runtime: O(1)
values
visibility: public
type: Map k v -> List v
Returns a list of all values in this map. Runtime: O(n)
entries
visibility: public
type: Map k v -> List (Tuple k v)
Returns a list of all keys and values in this map
forEach
visibility: public
type: Map k v -> (k -> v -> Unit) -> Unit
Executes the function for every key/value pair in this map Runtime: O(n)
mapValues
visibility: public
type: (k -> v -> v2) -> Map k v -> Map k v2
Maps function f over all entries of this map. Runtime: O(n)
filter
visibility: public
type: (k -> v -> Boolean) -> Map k v -> Map k v
Returns a map of the elements that match the given predicate. Runtime: O(n)
foldl
visibility: public
type: (b -> k -> v -> b) -> b -> Map k v -> b
Folds this map into a single value according to the folding function. Runtime: O(n)
all
visibility: public
type: (k -> v -> Boolean) -> Map k v -> Boolean
Returns true if the predicate is true for every entry in this map. Runtime: O(n)
any
visibility: public
type: (k -> v -> Boolean) -> Map k v -> Boolean
Returns true if the predicate is true for any entry in this map. Runtime: O(n)
concatMap
visibility: public
type: Concat (Map k v)
toList
visibility: public
type: Map k v -> List (Tuple k v)
Returns a list containing every key/value pair from this map. Runtime: O(n)
eqMap
visibility: public
type: {{ Equals k }} -> {{ Equals v }} -> Equals (Map k v)
withLinear
visibility: public
type: Map k v -> (Map k v -> b) -> Map k v
Creates a linear (mutable) version of the given map and applies the function to it.
Returns a forked (persistent) version of the returned linear map.
This function should be used when lots of expensive mutating operations have to be run on a map
and can be seen as a builder for the resulting map.
All functions that alter maps like put
, update
, remove
, etc.
will mutate a linear map.
Ex:
withLinear (Map.new ["a" ; 1, "b" ; 2, "c" ; 3]) \map ->
put "d" 4 map
remove "b" map
-> {"a" 1, "c" 3, "d" 4}
associate
visibility: public
type: (a -> Tuple k v) -> List a -> Map k v
Creates a map out of a list based on the given function. Runtime: O(n)
showMapp
visibility: private
type: Show k -> Show v -> Map k v -> String
showMap
visibility: public
type: {{ Show k }} -> {{ Show v }} -> Show (Map k v)