lineage/algorithms

Utilities for working with collections of dictionaries.

Values

pub fn collect(
  dicts: List(dict.Dict(a, b)),
) -> dict.Dict(a, List(b))

Collects a list of dictionaries into a single dictionary, grouping values by key into lists.

If the same key appears in multiple dictionaries, all corresponding values are gathered into a list. The order of values within each list reflects the order of the input dictionaries.

Examples

collect([dict.from_list([#("a", 1)]), dict.from_list([#("a", 2), #("b", 3)])])
// -> dict.from_list([#("a", [1, 2]), #("b", [3])])
Search Document