+def coalesce_by_creating_list(key, v1, v2):
+ from list_utils import flatten
+ return flatten([v1, v2])
+
+
+def coalesce_by_creating_set(key, v1, v2):
+ return set(coalesce_by_creating_list(key, v1, v2))
+
+
+def raise_on_duplicated_keys(key, v1, v2):
+ raise Exception(f'Key {key} is duplicated in more than one input dict.')
+
+
+def coalesce(
+ inputs: Iterator[Dict[Any, Any]],
+ *,
+ aggregation_function: Callable[[Any, Any], Any] = coalesce_by_creating_list
+) -> Dict[Any, Any]:
+ out: Dict[Any, Any] = {}
+ for d in inputs:
+ for key in d:
+ if key in out:
+ value = aggregation_function(d[key], out[key])
+ else:
+ value = d[key]
+ out[key] = value
+ return out
+
+
+def item_with_max_value(d: Dict[Any, Any]) -> Tuple[Any, Any]: