pipe-promise

1.0.0 • Public • Published

pipe-promise

Run asynchronous pipelines with helper functions for common array operations.

If the first argument isn't a promise, and no function return a promises, then the pipeline runs synchronously.

Helper functions

  • map
  • filter
  • reduce
  • foreach

Examples

Require:

const { pipe, map, filter, reduce, foreach } = require("pipe-promise")

Async pipeline using await:

await pipe(
    Promise.resolve([ 1, 2, 3 ]),
    filter(n => Promise.resolve(!== 1)),
    map(n => Promise.resolve(+ 1)),
    reduce((sum, n) => Promise.resolve(sum + n))
) // 7

Sync pipeline:

pipe(
    [ 1, 2, 3 ],
    filter(n => n !== 1),
    map(n => n + 1),
    reduce((sum, n) => sum + n)
) // 7

foreach:

foreach() runs sequentially and returns the input data

pipe(
    [ 1, 2, 3 ],
    foreach(console.log)
) // [ 1, 2, 3 ]

/pipe-promise/

    Package Sidebar

    Install

    npm i pipe-promise

    Weekly Downloads

    1

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    6.8 kB

    Total Files

    10

    Last publish

    Collaborators

    • nikolasrh