function aggregateGroups
aggregateGroups<T, A>(record: Readonly<Record<string, ReadonlyArray<T>>>,): Record<string, A>Applies the given aggregator to each group in the given grouping, returning the results together with the respective group keys
Examples
Example 1
Example 1
import { aggregateGroups } from "@std/collections/aggregate_groups"; import { assertEquals } from "@std/assert/assert_equals"; const foodProperties = { "Curry": ["spicy", "vegan"], "Omelette": ["creamy", "vegetarian"], }; const descriptions = aggregateGroups( foodProperties, (current, key, first, acc) => { if (first) { return `${key} is ${current}`; } return `${acc} and ${current}`; }, ); assertEquals(descriptions, { "Curry": "Curry is spicy and vegan", "Omelette": "Omelette is creamy and vegetarian", });
Type Parameters
Tinput type of an item in a group in the given grouping.
Atype of the accumulator value, which will match the returned record's values.