All Projects → kirillrogovoy → Promised Pipe

kirillrogovoy / Promised Pipe

A ramda.pipe-like utility that handles promises internally with zero dependencies

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Promised Pipe

rocket-pipes
Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀
Stars: ✭ 18 (-71.87%)
Mutual labels:  promise, pipe, composition, ramda
Functional Promises
Write code like a story w/ a powerful Fluent (function chaining) API
Stars: ✭ 141 (+120.31%)
Mutual labels:  async, promise, composition
Bugz
🐛 Composable User Agent Detection using Ramda
Stars: ✭ 15 (-76.56%)
Mutual labels:  ramda, composition, fp
Ppipe
pipes values through functions, an alternative to using the proposed pipe operator ( |> ) for ES
Stars: ✭ 192 (+200%)
Mutual labels:  async, promise, pipe
Metasync
Asynchronous Programming Library for JavaScript & Node.js
Stars: ✭ 164 (+156.25%)
Mutual labels:  async, promise, composition
Fun Task
Abstraction for managing asynchronous code in JS
Stars: ✭ 363 (+467.19%)
Mutual labels:  async, promise, fp
Awaitkit
The ES8 Async/Await control flow for Swift
Stars: ✭ 709 (+1007.81%)
Mutual labels:  async, promise
Wx Promise Pro
✨强大、优雅的微信小程序异步库🚀
Stars: ✭ 762 (+1090.63%)
Mutual labels:  async, promise
Then
🎬 Tame async code with battle-tested promises
Stars: ✭ 908 (+1318.75%)
Mutual labels:  async, promise
Nodespider
[DEPRECATED] Simple, flexible, delightful web crawler/spider package
Stars: ✭ 33 (-48.44%)
Mutual labels:  async, promise
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
Stars: ✭ 538 (+740.63%)
Mutual labels:  composition, fp
Vue Loadable
⏳ Improve your loading state control with pretty simple methods and helpers.
Stars: ✭ 23 (-64.06%)
Mutual labels:  async, promise
Create Request
Apply interceptors to `fetch` and create a custom request function.
Stars: ✭ 34 (-46.87%)
Mutual labels:  async, promise
P Map
Map over promises concurrently
Stars: ✭ 639 (+898.44%)
Mutual labels:  async, promise
Funfix
Functional Programming Library for JavaScript, TypeScript and Flow ✨⚡️
Stars: ✭ 596 (+831.25%)
Mutual labels:  async, fp
Ws Promise Client
PROJECT MOVED: https://github.com/kdex/ws-promise
Stars: ✭ 6 (-90.62%)
Mutual labels:  async, promise
Posterus
Composable async primitives with cancelation, control over scheduling, and coroutines. Superior replacement for JS Promises.
Stars: ✭ 536 (+737.5%)
Mutual labels:  async, promise
Node Qiniu Sdk
七牛云SDK,使用 ES2017 async functions 来操作七牛云,接口名称与官方接口对应,轻松上手,文档齐全
Stars: ✭ 44 (-31.25%)
Mutual labels:  async, promise
Breeze
Javascript async flow control manager
Stars: ✭ 38 (-40.62%)
Mutual labels:  async, promise
Emacs Async Await
Async/Await for Emacs
Stars: ✭ 47 (-26.56%)
Mutual labels:  async, promise

promised-pipe

npm version Build Status

Logo

A sweet composition of ramda.pipe and q.promised to make async pipes simple. No dependencies. Extremely lightweight. Fully tested.

Requirements

You only have to have Node 4+ or a ES5-compatible browser

Introduction

This library is extremely useful for those who use functions pipes (ramda.pipe, inverted underscore.compose, etc.), but struggle with composing both synchronous and asynchronous (Promise returning) functions in the same pipeline.

Install

Run:

npm i --save promised-pipe

Include:

const pipe = require('promised-pipe')
// or
import pipe from 'promised-pipe'

Usage

It is a function with the same API as ramda.pipe, except the created function will always return a Promise

const resultedFn = pipe(fn1, fn2, fn3)
resultedFn(args) // => Promise

There is a bunch of tests in test.js which are quite readable

Examples

You can play and run all of these examples by npm i ramda && node example.js (Node 6+ required).

Basic example with some simple math:

const inc = x => x + 1 // synchronous function
const mul3 = x => x * 3 // synchronous function
const div2promise = x => Promise.resolve(x / 2) // asynchronous function

const mathFn = pipe(
    inc,
    div2promise,
    mul3
)

mathFn(5).then(console.log) // 5 + 1 / 2 * 3 = 9

Numbers aren't so interesting! Example with fs:

const filePath = '/tmp/promised_pipe_example'
// "Promisify" fs modules
const readFile = path => new Promise((res, rej) => fs.readFile(path, (err, data) => err ? rej(err) : res(data)))
const writeFile = (path, data) => new Promise((res, rej) => fs.writeFile(path, data, (err) => err ? rej(err) : res(path)))

const fsFn = pipe(
    text => writeFile(filePath, text),
    path => readFile(path),
    text => text.toString(),
    text => text.toUpperCase(),
    text => writeFile(filePath, text).then(() => text)
)

fsFn('hello').then(console.log) // HELLO

Still isn't sexy, right? Let's add some Ramda to the previous example:

const R = require('ramda')
const readFileC = R.curry(readFile)
const writeFileC = R.curry(writeFile)
const writeToTmp = writeFileC(filePath + '_ramda')

const ramdaFsFn = pipe(
    writeToTmp,
    readFileC,
    R.toString,
    R.toUpper,
    R.tap(writeToTmp)
)

ramdaFsFn('hello, ramda').then(console.log) // HELLO, RAMDA

So you can easily mix functions which return non-promises and functions which return promises.

It is highly recommended to use it with Ramda since it will make your experience a lot better.

More on the topic

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].