DEV Community

Discussion on: A quick explanation about fast piping (-> and |.) in ReasonML

Collapse
 
hoichi profile image
Sergey Samokhov

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).

Collapse
 
mrmurphy profile image
Murphy Randle

Great answer!

Collapse
 
ryuheechul profile image
Heechul Ryu

Great answer! Thanks a lot!