https://github.com/mster/matflap
Faster alternative to Array.prototype.flatMap
https://github.com/mster/matflap
fast flatmap node
Last synced: about 1 month ago
JSON representation
Faster alternative to Array.prototype.flatMap
- Host: GitHub
- URL: https://github.com/mster/matflap
- Owner: mster
- License: mit
- Created: 2020-08-27T03:27:02.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-22T03:13:19.000Z (about 4 years ago)
- Last Synced: 2025-07-07T04:40:38.257Z (12 months ago)
- Topics: fast, flatmap, node
- Language: JavaScript
- Homepage:
- Size: 23.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Matflap
Faster alternative to Array.prototype.flatMap
``` js
const matflapped = matflap(array, mapFunction)
```
## matflap versus flatMap
See the [benchmarks](./benchmark/README.md).
## Going backwards ...
matflap retains functional parity with `Array.prototype.flatMap` while using ES features that have been in V8 since v4.9 (Node v6+).
``` js
$ nvm use lts/boron
Now using node v6.17.1 (npm v3.10.10)
$ node
> const matflap = require('matflap')
> a = matflap([1,2,3,4,5], e => [e, e*2])
[ 1, 2, 2, 4, 3, 6, 4, 8, 5, 10 ]
> [1,2,3,4,5].flatMap(e => [e, e*2])
TypeError: [1,2,3,4,5].flatMap is not a function
...
```
Running `npm test` on Node versions < v12.0 will fail because tests use `Array.prototype.flatMap`, which will not exist at that version.