Socket
Socket
Sign inDemoInstall

pipe-promise

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pipe-promise

Run asynchronous pipelines with helper functions for common array operations.


Version published
Weekly downloads
1
Maintainers
1
Install size
6.64 kB
Created
Weekly downloads
 

Readme

Source

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(n !== 1)),
    map(n => Promise.resolve(n + 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 ]

Keywords

FAQs

Last updated on 01 Jul 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc