Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        

# gen-map-fn



NPM Version



Travis Build


Coveralls


Bithound Status


License



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