https://github.com/ryanpcmcquen/flatmap-fast
A fast and modern flatMap for node. Monads for the win!
https://github.com/ryanpcmcquen/flatmap-fast
flatmap hacktoberfest
Last synced: 7 months ago
JSON representation
A fast and modern flatMap for node. Monads for the win!
- Host: GitHub
- URL: https://github.com/ryanpcmcquen/flatmap-fast
- Owner: ryanpcmcquen
- License: mpl-2.0
- Created: 2016-05-21T18:20:29.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-04-18T04:31:49.000Z (almost 4 years ago)
- Last Synced: 2025-08-17T15:36:32.340Z (7 months ago)
- Topics: flatmap, hacktoberfest
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/flatmap-fast
- Size: 30.3 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://gitpod.io/#https://github.com/ryanpcmcquen/flatmap-fast)
# flatmap-fast
The fastest `flatMap` this side of `node`.
Takes two arguments:
1. An array.
2. A callback function (optional).
```javascript
const flatMap = require("flatmap-fast");
const testArr = ['Hi', 'World'];
const splitWord = (word) => word.split('');
flatMap(testArr, splitWord);
// => ['H', 'i', 'W', 'o', 'r', 'l', 'd']
flatMap([1, 2, 3, 4], (x) => [x, x * 2]);
// => [1, 2, 2, 4, 3, 6, 4, 8]
```
Run `npm test` to test this flatMap against other flatMaps.
```javascript
$ node --version
v12.18.3
$ yarn test
yarn run v1.22.4
$ node test.js
// => flatMapFast took: 650.86651 milliseconds.
[
'H', 'i', 'W',
'o', 'r', 'l',
'd'
]
// => flatmapjs took: 667.361729 milliseconds.
[
'H', 'i', 'W',
'o', 'r', 'l',
'd'
]
// => flatMapFast took: 517.463478 milliseconds.
[
1, 2, 2, 4,
3, 6, 4, 8
]
// => flatmapjs took: 676.208413 milliseconds.
[
1, 2, 2, 4,
3, 6, 4, 8
]
Done in 2.74s.
```