3.8.2 • Published 4 years ago

@njlr/seq v3.8.2

Weekly downloads
21
License
MIT
Repository
github
Last release
4 years ago

seq

A simple library for manipulating generators and arrays in JavaScript.

Travis

Get Started

Install using Yarn:

yarn add @njlr/seq

Install using NPM:

npm install --save @njlr/seq

You can browse the documentation on GitHub.

Why? 🤔

  • Some of the built-in Array functions are mutating (e.g. Array.prototype.sort).
  • Many array functions are missing. Where is Array.prototype.flatMap?
  • A chain of array functions creates a new array at every stage: the operations are not lazy.
  • lodash and friends require either a wrapper object or binding for chaining calls. We use the pipeline operator (|>) to achieve this at compile-time!
  • This package is a good citizen. It has no dependencies and does not mutate any global objects.
  • The code is simple. You can review the whole thing in about an hour.

Demo

import * as seq from '@njlr/seq';

const xs = [ 1, 5, 1, 2, 7, 3, 3, 4, 5, 0 ] 
  |> seq.unique()
  |> seq.map(x => x * 2)
  |> seq.filter(x => x > 4)
  |> seq.sorted()
  |> seq.toArray;

// xs is [ 6, 8, 10, 14 ]

Since seq works on iterables, you can also use for...of loops:

import * as seq from '@njlr/seq';

for (const x of seq.range(10) |> seq.map(x => x * x)) {
  console.log(x);
}

This library also plays nicely with spread syntax!

const squares = [ ... seq.range(10) |> seq.map(x => x * x) ];

Development

Dependencies are managed by Yarn:

yarn install --pure-lockfile

To run all tests:

yarn test

To build the library:

yarn build

To build the documentation:

yarn docs

To release a new version:

npm publish --access public 
3.8.2

4 years ago

3.8.1

4 years ago

3.8.0

4 years ago

3.7.0

4 years ago

3.6.1

4 years ago

3.6.0

4 years ago

3.4.0

4 years ago

3.3.0

5 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago