JSPM

immutable-partition

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 30
  • Score
    100M100P100Q53105F
  • License MIT

A partition helper returning ImmutableJS structures

Package Exports

  • immutable-partition

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (immutable-partition) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

immutable-partition

Build Status

A partitioning helper returning an immutablejs Map of Lists:

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

npm i -S immutable-partition

# or

yarn add immutable-partition

Usage

partition takes the two following arguments and returns a Map<K:string, V:List>.

  • 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:

partition(keyForValue, reducible)
// or
partition(keyForValue)(reducible)