I made Pipeline Decorator for one who wants to use Pipeline Operator in JavaScript ๐Ÿšฐ

Few days back, I wrote an article about how helpful the Pipeline Operator could be for some use cases.

Two JavaScript experimental features that Iโ€™m already dreaming of implementing on my codebase.
Ever heard of AggregateError and Pipeline Operator (|>)

I shared this article on multiple forums and a lot of users from Reddit gave interesting thought, but one of them gave a rough sketch of writing pipeline decorator using curry. So I went ahead and gave it a try, and here I have it. I just thought it will be useful for anyone looking ways for writing cleaner code.

var-kar/pipe-decorator
A pipe decorator(Pipeline Operator) with promise callbacks for JavaScript - var-kar/pipe-decorator

It is a very tiny library with only 45 lines of code. It has room for loads of improvements. I welcome you to contribute to the codebase or you can use this decorator with your favourite libraries like lodash, underscore etc.

Syntax

pipe(arity)(Function)...();
Pipeline Decoratorย 

Notice how it ends with an empty invocation, this will make sure it returns the result.

I knew similar functionality exists with libraries like RamdaJS. But, I just thought it will be good to learn and create a smaller library than Ramda.

Promise

The library also handles promise, for example, you can do pre and post-processing of data along with Promise to make it more useful.

Notice how step 2 passes two arguments to _.difference function and notice step 4, get results from Promise and pass it on to _.filter function along with the email to be found as a second argument. ย 

Use cases

  1. Makes your code clean and easy to read
  2. Better than chaining or at least in my opinion
  3. Makes multiple Promise handling much cleaner and readable.
  4. Pre and post-processing of data for a promise gets easier and cleaner.

Summary

It's always good to share with a wider JavaScript community to get a different perspective. I'm for sure going to give it a try on my next project to reduces the number of lines of code I write.

I welcome you to contribute and make it even more useful covering more use cases.

Finally, please share your thought. Thank you.