1.0.0 • Published 7 years ago

gen-map-fn v1.0.0

Weekly downloads
7
License
MIT
Repository
github
Last release
7 years ago

gen-map-fn

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