Function aggregateGroups
- aggregate
Groups <T, A>(record, aggregator): Record<string, A> Type Parameters
Parameters
Returns Record<string, A>
A record with the same keys as the input record, but with the values being the result of applying the aggregator to each group.
Example: Basic usage
import { aggregateGroups } from "@std/collections/aggregate-groups";
import { assertEquals } from "@std/assert";
const foodProperties = {
Curry: ["spicy", "vegan"],
Omelette: ["creamy", "vegetarian"],
};
const descriptions = aggregateGroups(
foodProperties,
(current, key, first, acc) => {
return first
? `${key} is ${current}`
: `${acc} and ${current}`;
},
);
assertEquals(descriptions, {
Curry: "Curry is spicy and vegan",
Omelette: "Omelette is creamy and vegetarian",
});
Applies the given aggregator to each group in the given grouping, returning the results together with the respective group keys