Live data from Hacker News

The JavaScript Pipeline Operator

yanis.blog

11–20 of 63 posts

Re: The JavaScript Pipeline Operator

#11
post #8

>The difference is in how we read it. With pipeline operator data flows from left to the right, and thus making it much more comprehensible without the need to introduce extra variables. Why you need operator? Can't it be done with a function? pipe(64,Math.sqrt)

Your example falls apart when making multiple function calls.

Please explain.

Re: The JavaScript Pipeline Operator

#12
post #8

>The difference is in how we read it. With pipeline operator data flows from left to the right, and thus making it much more comprehensible without the need to introduce extra variables. Why you need operator? Can't it be done with a function? pipe(64,Math.sqrt)

Your example falls apart when making multiple function calls.

Not quite sure what you mean. But how do you chain multiple functions?

Re: The JavaScript Pipeline Operator

#13
post #11

Earlier quoted context omitted.

Your example falls apart when making multiple function calls.

Please explain.

64 |> Math.sqrt becomes pipe(64, Math.sqrt)

64 |> Math.sqrt |> Math.sin becomes pipe(pipe(64, Math.sqrt), Math.sin)

Assuming pipe was smart and took varags we can make this better.

64 |> Math.sqrt |> Math.sin becomes pipe(64, Math.sqrt, Math.sin)

Re: The JavaScript Pipeline Operator

#14
post #4

ES6 was needed, but I think js should hit the breaks for new language features for a while.

I tend to agree with you. The thing is that most people would agree but at the time everyone wants different features. Me personally I even think we could be better without classes and all that "pretend you're writing Java" nonsense

Re: The JavaScript Pipeline Operator

#15
post #13
post #11

Earlier quoted context omitted.

Please explain.

64 |> Math.sqrt becomes pipe(64, Math.sqrt) 64 |> Math.sqrt |> Math.sin becomes pipe(pipe(64, Math.sqrt), Math.sin) Assuming pipe was smart and took varags we can make this better. 64 |> Math.sqrt |> Math.sin becomes pipe(64, Math.sqrt, Math.sin)

I guess you could make pipe variadic:

    function pipe(val, ...funcs) {
      for (let f of funcs) val = f(val);
    }
EDIT: seems like I got ninja'd by an edit :)

Re: The JavaScript Pipeline Operator

#16
post #13
post #11

Earlier quoted context omitted.

Please explain.

64 |> Math.sqrt becomes pipe(64, Math.sqrt) 64 |> Math.sqrt |> Math.sin becomes pipe(pipe(64, Math.sqrt), Math.sin) Assuming pipe was smart and took varags we can make this better. 64 |> Math.sqrt |> Math.sin becomes pipe(64, Math.sqrt, Math.sin)

JavaScript argument list evaluation is from left to right, right?

   pipe(64,Math.sqrt,Math.sin)
and

   pipe(pipe(64, Math.sqrt), Math.sin)
are equivalent.

Re: The JavaScript Pipeline Operator

#18
post #3

Earlier quoted context omitted.

Good point. I've heard about it but never could quite understand if it's useful enough. Can you share some public repos where it's being used?

the official web-site is pretty informative and has a ton of samples.. https://rxjs-dev.firebaseapp.com/api - take a look at operators section for example. as for public repos - nowadays any modern front-end app that is built with Angular is using rxjs - it's de factor standard for data processing in angular world.

Thanks sir. Will take a look

Re: The JavaScript Pipeline Operator

#19
post #16
post #13

Earlier quoted context omitted.

64 |> Math.sqrt becomes pipe(64, Math.sqrt) 64 |> Math.sqrt |> Math.sin becomes pipe(pipe(64, Math.sqrt), Math.sin) Assuming pipe was smart and took varags we can make this better. 64 |> Math.sqrt |> Math.sin becomes pipe(64, Math.sqrt, Math.sin)

JavaScript argument list evaluation is from left to right, right? pipe(64,Math.sqrt,Math.sin) and pipe(pipe(64, Math.sqrt), Math.sin) are equivalent.

If you just define a simple function

pipe(val, func) => func(val)

then they wouldn't be equivalent but you absolutely could define pipe so they would be.

Post reply on HN