https://github.com/agrafix/flow-sequence
JavaScript: Efficient chaining of operations of array like structures
https://github.com/agrafix/flow-sequence
Last synced: about 2 months ago
JSON representation
JavaScript: Efficient chaining of operations of array like structures
- Host: GitHub
- URL: https://github.com/agrafix/flow-sequence
- Owner: agrafix
- Created: 2018-06-22T05:30:44.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-26T04:06:09.000Z (almost 8 years ago)
- Last Synced: 2025-03-08T20:48:56.300Z (over 1 year ago)
- Language: JavaScript
- Size: 123 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# flow-sequence
[](https://circleci.com/gh/agrafix/flow-sequence) 
An (experimental) attempt to allow chaining operations on `Array` without traversing the array
multiple times. In other words: A chain of actions on an array should always be `O(n)` where `n` is
the number of elements in the array.
In the given example all element should only be traversed once:
```javascript
import {chain} from 'flow-sequence';
const op = chain()
.filter((x) => x > 2)
.map((x) => x + 1)
.filter((x) => x > 4)
.flatMap((x) => [x, x])
.optimize();
console.log(op.run([1, 2, 3, 4, 5]));
```
## Install
Get from npm via `npm install flow-sequence` or `yarn add flow-sequence`. Comes with flow types!
## Benchmarks
```
10 elements, no early failing: naive chaining x 337,465 ops/sec ±0.59% (91 runs sampled)
10 elements, no early failing: flow sequence chaining x 1,142,422 ops/sec ±2.46% (87 runs sampled)
100 elements, no early failing: naive chaining x 24,835 ops/sec ±1.41% (83 runs sampled)
100 elements, no early failing: flow sequence chaining x 132,714 ops/sec ±0.80% (86 runs sampled)
10000 elements, no early failing: naive chaining x 7.71 ops/sec ±1.36% (23 runs sampled)
10000 elements, no early failing: flow sequence chaining x 1,345 ops/sec ±0.77% (86 runs sampled)
10000 elements, early failing: naive chaining x 7,931 ops/sec ±1.40% (86 runs sampled)
10000 elements, early failing: flow sequence chaining x 5,594 ops/sec ±1.46% (85 runs sampled)
10000 elements, midway failing: naive chaining x 2,019 ops/sec ±1.09% (88 runs sampled)
10000 elements, midway failing: flow sequence chaining x 4,608 ops/sec ±1.29% (86 runs sampled)
```