crow/col/map.crow
(source)
map
[k
, v
] record
(has non-public fields)
Immutable unordered map type.
A map is logically a collection of key-value pairs ((k, v)
).
A key can appear at most once, and given a key, you can access the associated value in O(1).
There should be ==
, <=>
, and hash-mix
functions defined for the key type k
.
==
[k
, v
] bool
(a
k
[
v
]
, b
k
[
v
]
) k
key
, v
equal
key
equal
new
[k
, v
] k
[
v
]
(...
a
(k
, v
) tuple2
array
) k
key
key
Creates a new map from the given key-value pairs.
Later pairs overwrite earlier pairs with the same key.
to
[k
, v
] k
[
v
]
(a
(k
, v
) tuple2
array
) k
key
key
Converts a list of pairs to a map.
Later pairs overwrite earlier pairs with the same key.
to
[k
, v
] (k
, v
) tuple2
array
(a
k
[
v
]
) k
key
key
Returns all pairs in the map.
is-empty
[k
, v
] bool
(a
k
[
v
]
) k
key
key
True iff the map has no entries.
size
[k
, v
] nat64
(a
k
[
v
]
) k
key
key
Number of pairs.
subscript
[k
, v
] v
?
(a
k
[
v
]
, key
k
) k
key
key
Gets the value associated with a key.
Returns an empty option if the key is not in a
.
in
[k
, v
] bool
(key
k
, a
k
[
v
]
) k
key
key
true
iff the key is in the map.
~
[k
, v
] k
[
v
]
(a
k
[
v
]
, anonymous
(k
, v
) tuple2
) k
key
key
Associates the key with the value.
This may overwrite the key if it's already in a
, or add a new entry.
~~
[k
, v
] k
[
v
]
(a
k
[
v
]
, pairs
k
[
v
]
) k
key
key
Adds/updates many entries to a
.
keys
[k
, v
] k
array
(a
k
[
v
]
) k
key
key
values
[k
, v
] v
array
(a
k
[
v
]
) k
key
key
-
[k
, v
] k
[
v
]
(a
k
[
v
]
, key
k
) k
key
key
Removes a key and its associated value.
If the key is not in the map, returns a
unmodified.
(To distinguish that case, and to get the removed value, use try-remove
.)
try-remove
[k
, v
] (v
, k
[
v
]
) tuple2
?
(a
k
[
v
]
, key
k
) k
key
key
Removes a key and its associated value, and returns the value and the new map.
If the key is not in the map, returns an empty option.
iterate
[k
, v
] bool
(a
k
[
v
]
, f
mut
bool
((k
, v
) tuple2
))
map-builder
[k
, v
] record
mut
(has non-public fields)
build
[k
, v
] k
[
v
]
(a
build-options
, f
mut
void
((k
, v
) map-builder
)) k
key
key