Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arnaudrinquin/immutable-partition
A partitioning helper returning ImmutableJS structures
https://github.com/arnaudrinquin/immutable-partition
Last synced: 2 months ago
JSON representation
A partitioning helper returning ImmutableJS structures
- Host: GitHub
- URL: https://github.com/arnaudrinquin/immutable-partition
- Owner: ArnaudRinquin
- License: mit
- Created: 2016-12-17T12:15:38.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-19T09:50:41.000Z (about 8 years ago)
- Last Synced: 2024-10-18T19:43:37.348Z (3 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/immutable-partition
- Size: 40 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# immutable-partition
[![Build Status](https://travis-ci.org/ArnaudRinquin/immutable-partition.svg?branch=master)](https://travis-ci.org/ArnaudRinquin/immutable-partition)
A partitioning helper returning an [`immutablejs`](https://facebook.github.io/immutable-js/) Map of Lists:
```js
import partition from 'immutable-partition'const someNumbers = List.of(0, 1, 2, 3)
const evenOrOdd = (number) => number % 2 === 1 ? 'odd' : 'even'
const partitions = partition(evenOrOdd, someNumbers)
console.log(partitions.toString())
// > Map { "even": List [ 0, 2 ], "odd": List [ 1, 3 ] }
```## Install
```sh
npm i -S immutable-partition# or
yarn add immutable-partition
```## Usage
`partition` takes the two following arguments and returns a `Map`.
* `keyForValue(value: any): string` must return a string
* `reducible` just needs to have a `reduce` function so it can be any `immutablejs` structure, a regular array or anything that acts like one.`partition` is curried so it can be called in two ways:
```js
partition(keyForValue, reducible)
// or
partition(keyForValue)(reducible)
```