gen-map-fn

1.0.0 • Public • Published

gen-map-fn

NPM Version Travis Build Coveralls Bithound Status License

Map function over iterator capturing the iterator return value

Install

npm i -S gen-map-fn

Signatures

genMapFn :: (Function fn, Iterator it) => (fn, it, ...args) -> it
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')

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

git clone https://github.com/nhz-io/gen-map-fn
cd gen-map-fn
npm i
npm start

License MIT

Version 1.0.0

Package Sidebar

Install

npm i gen-map-fn

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • nhz-io