Nope. |> is a regular pipe and it passes the result of the left expression as a last argument of the function on the right. This is why, unlike Belt, in a lot (maybe in the most) of FP libraries functions like map have a signature of map(f, list), not map(list, f), because you’re supposed to call them like: someList |> map(f1) |> filter(f2), which is basically the same as filter(f2, map(f1, someList)). But functions in Belt have the same parameter order that in the vanilla JS (maybe that was one of the reasons), like this: map(list, f). That means that the regular pipe won’t work, so you have to use fast pipes, that looks about the same, someList -> map(f1) -> filter(f2), but are desugared as: filter(map(someList, f1), f2).
The other reason why fast pipe (and the corresponding parameter order) might be preferable is that it’s better for completion. Once you type expression ->, your IDE can suggest some functions the first argument of which has the type of expression. With regular pipes, it’s a more complicated task (for various reasons, most of which I may not understand).
I’m a professional software writer specialized in Web technologies and engaged in indie application development. I consider myself to be a man of faith. I pursue honesty, integrity, and compassion.
I love working on stuff that boosts developers' (or my) productivity.
I pretend to write good code until I actually do 😉.
I am also the creator of https://keytty.com.
Nope.
|>
is a regular pipe and it passes the result of the left expression as a last argument of the function on the right. This is why, unlike Belt, in a lot (maybe in the most) of FP libraries functions likemap
have a signature ofmap(f, list)
, notmap(list, f)
, because you’re supposed to call them like:someList |> map(f1) |> filter(f2)
, which is basically the same asfilter(f2, map(f1, someList))
. But functions in Belt have the same parameter order that in the vanilla JS (maybe that was one of the reasons), like this:map(list, f)
. That means that the regular pipe won’t work, so you have to use fast pipes, that looks about the same,someList -> map(f1) -> filter(f2)
, but are desugared as:filter(map(someList, f1), f2)
.The other reason why fast pipe (and the corresponding parameter order) might be preferable is that it’s better for completion. Once you type
expression ->
, your IDE can suggest some functions the first argument of which has the type ofexpression
. With regular pipes, it’s a more complicated task (for various reasons, most of which I may not understand).Great answer!
Great answer! Thanks a lot!