Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.
/ pppipe Public archive

proxied promise pipe - ppipe with a twist

Notifications You must be signed in to change notification settings

egeozcan/pppipe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IMPORTANT

This is an experiment which uses Proxies and requires you to use eval (ugh). Never use this in production. Being hacky behind the scenes is one thing, encouraging the user to use eval is another. This code exists as a thought experiment.

You can use ppipe for your projects, as a sane alternative.

pppipe

pipes values through functions, an alternative to using the proposed pipe operator ( |> ) for ES.

Supports functions returning promises too. In that case, the result of the chain will also be a promise. This is similar to the proposed support for await in the chained functions.

Installation

npm install pppipe

All features at a glance

/* used for inserting the result to a specific location
in a multi-parameter function*/
const _ = pppipe._;
const add = (x, y) => x + y;
const double = x => 2 * x;
const square = x => Math.pow(x, 2);
const divide = (x, y) => x / y;
const delayRes = x => 
  new Promise(resolve => setTimeout(() => resolve(x), 100));
const ctx = x => eval(x);

pppipe(1, ctx).add(1).double().square().divide(_, 8); // 2
pppipe(1, ctx).add(1).double().square().delayRes().divide(_, 8)
  .then(x => console.log(x)); // Logs 2 after ~100ms

Look at the test/test.js for more examples.

About

proxied promise pipe - ppipe with a twist

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published