JSPM

fast-iterator

0.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 285
  • Score
    100M100P100Q93976F
  • License MIT

Fast execution of an array of functions with the same value as input that can be altered.

Package Exports

  • fast-iterator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fast-iterator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fast-iterator

js-standard-style Build Status

Fast execution of an array of functions with the same value as input that can be altered.

Install

npm i fast-iterator --save

Usage

const fast = require('fast-iterator')

fast(
  [fn1, fn2, fn3], // the array of functions to execute
  { context: true } // a custom context for every function
)(
  iterator.bind({ a: 'a', b: 'b' }), // an iterator function to pass custom parameters
  { hello: 'world' }, // the value to update
  done // the function to call once the work has been done
)

function fn1 (a, b, result, done) {
  console.log(a, b, result, this)
  done(null, { ciao: 'mondo' })
}

function fn2 (a, b, result, done) {
  console.log(a, b, result, this)
  done(null, { winter: 'is coming' })
}

async function fn3 (a, b, result) {
  console.log(a, b, result, this)
  return { winter: 'has come' }
}

function iterator (fn, result, done) {
  return fn(this.a, this.b, result, done)
}

function done (err, result) {
  console.log(err || result, this)
}

Output:

a b { hello: 'world' } { context: true }
a b { ciao: 'mondo' } { context: true }
a b { winter: 'is coming' } { context: true }
{ winter: 'has come' } { context: true }

If you need to release the internal Object holder for performances reasons, you can call the fourth parameter of the iterator: release.

function iterator (fn, result, done, release) {
  if (someCondition) return release()
  return fn(this.a, this.b, result, done)
}

Acknowledgements

This project is kindly sponsored by LetzDoIt.

License

Licensed under MIT.