What is a Pipeline Operator

Pipeline operator is still in draft stage and it might be part of next Js release.
It’s a backwards-compatible way of streamlining chained function calls in a readable, functional manner

let result = “hello”
|> doubleSay
|> capitalize
|> exclaim;

/* same as let result = exclaim(capitalize(doubleSay("hello"))); / / result is “Hello, hello!” */

Here is another example

type person = { score: int };
let me = { score: 25 };
let double = (x) => x + x;
let add = (x, y) => x + y;
let boundScore = (lower, upper, score) => max(lower, min(upper, score));

let newScore = me.score
|> double
|> (it) => add(7, it)
|> (it) => boundScore(0, 100, it);
/* same as boundScore(0, 100, add(7, double(me.score))); */

Uday Ogra

Connect with me at http://facebook.com/tendulkarogra and lets have some healthy discussion :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *