Skip to content

Maps

Map<K, V> is a dictionary with keys of type K and values of type V. Use %{key => value} for a map literal or gale_std.map.from_list to build one from key-value tuples. %{} is an empty map; {} is the empty tuple.

mod maps
alias gale_std.map
pub fn scores() -> Map<String, Integer> {
map.from_list([{"ada", 36}, {"al", 41}])
}
pub fn score(scores: Map<String, Integer>, name: String) -> Option<Integer> {
map.get(scores, name)
}

gale_std.map.get returns Option<V>, preserving the distinction between a missing key (None) and a stored nil (Some(nil)).