Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aeinbu/groupby

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aeinbu/groupby

Helper functions for doing "group by" type transformations on collections using reducers

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-93.1%
Maintainers
1
Weekly downloads
 
Created
Source

@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)
// Result:
// [
//     [key: "Rome", values: ["Tony", "Mary", "Peter"],
//     ["Lkey: ondon", values: ["Peter", "Elisabeth"],
//     ["key: Paris", values: ["Francois"]
// ]

const resultsAsDictionary = resultsAsArray.reduce(toDictionary(x => name))
// Result:
// {
//     "Rome": ["Tony", "Mary", "Peter"],
//     "London": ["Peter", "Elisabeth"],
//     "Paris": ["Francois"]
// }

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))
// With the same results as above:
// {
//     "Rome": ["Tony", "Mary", "Peter"],
//     "London": ["Peter", "Elisabeth"],
//     "Paris": ["Francois"]
// }

Also, look in the tests directory for more examples. The tests demonstrate at least a dosen different ways to use this library

Keywords

FAQs

Package last updated on 16 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc