qol_gleam/qol_dict

Values

pub fn map_keys(
  in dict: dict.Dict(k, v),
  with fun: fn(k, v) -> a,
) -> dict.Dict(a, List(v))

Updates all keys in a given dict by calling a given function on each key and value.

Examples

from_list([#(1, "a"), #(2, "b"), #(3, "c"), #(4, "d"), #(5, "e"), #(6, "f")])
|> map_keys(fn(key, _value) { key % 3 })
// -> from_list([#(0, ["f", "c"]), #(1, ["d", "a"]), #(2, ["e", "b"])])

Origin

This function is commonly expected from other programming language.

Search Document