Not that I necessarily disagree, but one counter argument would be "why even use the pipe method? You could just say
square(increment(square(2)))
and get the same result, right?"
The point is readability. It's UX for the programmer, reducing cognitive load in understanding what's going on. Pipes are fantastic in the terminal and have never been replaced there because they are very simple glue piecing together the complex bits with a simple-to-understand model.
If we can have that in JS, I'd be quite pleased even if there are other ways to do the same thing.
The advantage of the operator and the `pipe` helper over regular function composition is that you can emphasize the flow of data through a pipeline of functions.
The only advantage in readability I see here is that the operator is hard to mistake for anything else, it sticks out of the code, more than a seemingly regular function call. But this is not an advantage that justifies introducing the operator.
Other than that, UX and cognitive load is the same.
Pipes can indeed be fantastic! ;)
*
Apropos composition: why not add a composition operator while we're at it? Or we could define something like:
For me there is also something more ineffable that's important here. A question of whether adding a new built-in operator fits within the general philosophy or some sort of "look & feel" of the language, or whatever. I think JavaScript seems to be quite conservative, when it comes to bringing in new operators. Perhaps that's a good thing. Maybe not. But so far, I remain unconvinced.
Fuzzy words and your opinon, so can't exactly argue with that.
But here's a try ;)
I take it that the meaning behind the words you used is:
clean:
no need for `pipe(` prefix and `)` postfix
expressive:
can convey a pipeline in a distinctive and unique way
(with a special operator as opposed to regular function)
Let me use the same words, but with different meaning, to say "the pipe function is much cleaner and expressive IMO".
The meaning would be:
clean:
looks (is) the same as regular function application,
no need for dirtying the syntax up with
a special operator
need to only press one extra key per operand/argument
(,) as opposed to 3 (shift+|,>) ;)
expressive:
can convey a pipeline just as well as the operator;
it's a regular function, so it's first class,
unlike the operator
it's variadic, so you can combine it with
spread operator syntax like:
pipe(data, ...pipeline1, ...pipeline2)
// where pipeline1 and pipeline2
// are arrays of functions
The point is readability. It's UX for the programmer, reducing cognitive load in understanding what's going on. Pipes are fantastic in the terminal and have never been replaced there because they are very simple glue piecing together the complex bits with a simple-to-understand model.
If we can have that in JS, I'd be quite pleased even if there are other ways to do the same thing.