Skip to content

danielrbradley/collection-fns

Repository files navigation

Collection Functions

styled with prettier Travis Coveralls Dev Dependencies Greenkeeper badge

Really simple functions for working with built-in collection types, inspired by F#'s collection modules design.

Features

  • Covers, iterables, arrays, maps and sets.
  • Composable functional design.

Example usage

Calculating primes without loops:

const primes = pipe(init(x => x, 100))
  .then(
    map(x => ({
      x,
      factors: pipe(init(i => i + 1, x))
        .then(filter(y => x % y === 0))
        .result
    }))
  )
  .then(filter(num => Iterables.length(num.factors) === 2))
  .then(map(num => num.x))
  .then(toArray)
  .result

Importing library

You can import the generated bundle to use the whole library:

import myLib from 'collection-fns'

Additionally, you can import the specific modules from dist/lib:

import { groupBy } from 'collection-fns/dist/lib/iterable'

NPM scripts

  • yarn t: Run test suite
  • yarn start: Run yarn build in watch mode
  • yarn test:watch: Run test suite in interactive watch mode
  • yarn test:prod: Run linting and generate coverage
  • yarn build: Generate bundles and typings, create docs
  • yarn lint: Lints code
  • yarn commit: Commit using conventional commit style (husky will tell you to use it if you haven't 😉)