# data-collectors

> A collection of composable reduction operations for arbitrary streams of values

Latest version **1.0.5** (published 2019-10-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install data-collectors
pnpm add data-collectors
yarn add data-collectors
bun add data-collectors
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2019-10-19 |
| First published | 2018-12-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 68.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Pedro M. Silva |
| Maintainers | pedromsilva |
| Keywords | js, iterables, streams, data, values, collectors, reductors, functional programming, composition |

## Links

- npm: https://www.npmjs.com/package/data-collectors
- Repository: https://github.com/pedromsilvapt/data-collectors
- Homepage: https://github.com/pedromsilvapt/data-collectors#readme
- Issues: https://github.com/pedromsilvapt/data-collectors/issues
- npm.io page: https://npm.io/package/data-collectors

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.5 (latest) — 2019-10-19
- 1.0.4 — 2019-08-21
- 1.0.3 — 2019-08-21
- 1.0.2 — 2019-08-21
- 1.0.1 — 2018-12-12
- 1.0.0 — 2018-12-06

## README

# Collectors

> A collection of composable reduction operations for arbitrary streams of values

# Installation
```shell
npm install --save data-collectors
```

# Usage
Useful to reduce data in many ways.

```typescript
import { collect, groupingBy, first, mapping, sorting } from 'data-collectors';

interface Person {
    role : 'admin' | 'moderator' | 'user';
    id : number;
    name : string;
}

const array : Person[] = [ { role: 'admin', id: 1, name: 'John' }, { role: 'user', id: 2, name: 'David' }, { role: 'user', id: 3, name: 'Peter' } ];

let collector = groupingBy( user => user.role, groupingBy( user => user.id, first() ) );

collect( array, collector ); // Map { 'admin' => Map{ 1 => ... }, 'user' => { 2 => ..., 3 => ... } };

let collector2 = groupingBy( user => user.role, mapping( user => user.id ) );

collect( array, collector2 ); // Map { 'admin' => [ 1 ], 'user' => [ 2, 3 ] };

// Sort the array by name
collect( array, sorting( ( a, b ) => a.name.localeCompare( b.name ) ) );  // [ { ... name: 'David' }, { ... name: 'John' }, { ... name: 'Peter' } ]
```

Note that while some collectors can only be used on their own (like `first` or `last`), others can be composed (like `mapping` accepts a second argument after the mapper function, or `groupingBy` which also accepts a second optional collector argument (default is `toArray()`) that will be applied to each value of the resulting Map).

---
_Source: https://npm.io/package/data-collectors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
