Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nhz-io/gen-map-fn
Map function over iterator capturing the iterator return value
https://github.com/nhz-io/gen-map-fn
functional generator iterator map
Last synced: 3 days ago
JSON representation
Map function over iterator capturing the iterator return value
- Host: GitHub
- URL: https://github.com/nhz-io/gen-map-fn
- Owner: nhz-io
- License: mit
- Created: 2017-06-16T21:43:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-16T22:19:43.000Z (over 7 years ago)
- Last Synced: 2024-12-10T20:51:56.873Z (14 days ago)
- Topics: functional, generator, iterator, map
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gen-map-fn
Map function over iterator capturing the iterator return value
## Install
```sh
npm i -S gen-map-fn
```## Signatures
```hs
genMapFn :: (Function fn, Iterator it) => (fn, it, ...args) -> it
```
```hs
curriedGenMapFn :: (Function fn, Iterator it) => fn -> (it, ...args) -> it
```## Use case
* You are within a generator function
* You have a source iterator that you are pulling the values from
* You want to transform those values
* You need the return value of the source iterator
* You want to minimize boilerplate and just use: `result = yield* iterator`## Usage Example
> For curried version use: `const curriedGenMapFn = require('gen-map-fn/curried')`
```js
const genMapFn = require('gen-map-fn')function* it() {
yield* [1, 2, 3]return 'ok'
}const mul = (v, m) => v * m
function* gen(it, m) {
it = genMapFn(mul, it, m)console.log('Done:', yield* it)
}console.log('Multiplying [1, 2, 3] by 5')
console.log('Result:', [...gen(it(), 5)])
```## Dev
```sh
git clone https://github.com/nhz-io/gen-map-fn
cd gen-map-fn
npm i
npm start
```## License [MIT](LICENSE)
## Version 1.0.0