@aeinbu/groupby
Helper functions for doing "group by" type transformations on collections using reducers
How to install
With npm
npm install @aeinbu/groupby
...or with yarn
yarn add @aeinbu/groupby
How to use
const people = [
{name: "Tony", residence: "Rome"},
{name: "Mary", residence: "Rome"},
{name: "Peter", residence: "London"},
{name: "Peter", residence: "Rome"},
{name: "Elisabeth", residence: "London"},
{name: "Francois", residence: "Paris"}
]
const resultsAsArray = people.reduce(x => x.name, x => x.residence)
const resultsAsDictionary = resultsAsArray.reduce(toDictionary(x => name))
Since the reduction from groupBy is an array, the above two transforms can be chained, like this:
const chainedResults = people
.reduce(x => x.name, x => x.residence)
.reduce(toDictionary(x => name))
Also, look in the tests
directory for more examples. The tests demonstrate at least a dosen different ways to use this library