# @f/reduce-key

> Reduce a keyed map (or array), using a selector function.

Latest version **1.2.0** (published 2015-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @f/reduce-key
pnpm add @f/reduce-key
yarn add @f/reduce-key
bun add @f/reduce-key
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2015-12-16 |
| First published | 2015-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | f |

## Links

- npm: https://www.npmjs.com/package/@f/reduce-key
- Repository: https://github.com/micro-js/reduce-key
- Homepage: https://github.com/micro-js/reduce-key#readme
- Issues: https://github.com/micro-js/reduce-key/issues
- npm.io page: https://npm.io/package/@f/reduce-key

## Dependencies (2)

- [@f/is-undefined](https://npm.io/package/@f/is-undefined.md) ^1.0.0
- [@f/clone-shallow](https://npm.io/package/@f/clone-shallow.md) ^1.1.2

## Recent versions

- 1.2.0 (latest) — 2015-12-16
- 1.1.1 — 2015-12-16
- 1.1.0 — 2015-12-16

## README

# reduce-key

[![Build status][travis-image]][travis-url]
[![Git tag][git-image]][git-url]
[![NPM version][npm-image]][npm-url]
[![Code style][standard-image]][standard-url]

Reduce a keyed map (or array), using a selector function.

## Installation

    $ npm install @f/reduce-key

## Usage

One thing that often prevents the fully declarative construction of reducers is keyed maps (e.g. objects of the form `{[key]: entity}`, or arrays). reduceKey solves this problem, by allowing you to specify a selector function that decides which subject to apply the reducer to.


```js
var reduceKey = require('@f/reduce-key')

const todoReducer = combineReducers({
  text: handleActions({
    [TODO_SET_TEXT]: (state, {text}) => text,
    [TODO_CLEAR_TEXT]: () => ''
  }),
  completed: handleActions({
    [TOGGLE_COMPLETED]: (state) => !state
  })
})

export default combineReducers({
  todos: reduceKey((state, {idx}) => idx, todoReducer)
})
```

## API

### reduceKey(select, reduce)

- `select` - A function that accepts state and action and returns the key. If `select` returns `null`, `undefined`, or `false`, the reducer will not be called. So you are free to do things like:
             `(state, action) => action.payload.key` - even if your actions do not always contain key.
- `reduce` - A reducer that reduces over the entities within the map or array.

**Returns:** A reducer that reduces over the sub-object in the key and returns a new copy of the map, with the sub-object specified by `select(state, action)` updated by your reducer.

## License

MIT

[travis-image]: https://img.shields.io/travis/micro-js/reduce-key.svg?style=flat-square
[travis-url]: https://travis-ci.org/micro-js/reduce-key
[git-image]: https://img.shields.io/github/tag/micro-js/reduce-key.svg
[git-url]: https://github.com/micro-js/reduce-key
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat
[standard-url]: https://github.com/feross/standard
[npm-image]: https://img.shields.io/npm/v/@f/reduce-key.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@f/reduce-key

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