>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.
The JavaScript Pipeline Operator
11–20 of 63 posts
Re: The JavaScript Pipeline Operator
#12>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.
Re: The JavaScript Pipeline Operator
#13Earlier quoted context omitted.
Your example falls apart when making multiple function calls.
Please explain.
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
#14ES6 was needed, but I think js should hit the breaks for new language features for a while.
Re: The JavaScript Pipeline Operator
#15Earlier 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)
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
#16Earlier 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)
pipe(64,Math.sqrt,Math.sin)
and pipe(pipe(64, Math.sqrt), Math.sin)
are equivalent.Re: The JavaScript Pipeline Operator
#17Re: The JavaScript Pipeline Operator
#18Earlier 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.
Re: The JavaScript Pipeline Operator
#19Earlier 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.
pipe(val, func) => func(val)
then they wouldn't be equivalent but you absolutely could define pipe so they would be.