A simple note on pipe first and pipe last


I made a gist of a simple note on pipe first(->) and pipe last(|>)

Hopefully this would be helpful if you are a bit confused about them like I was.


The |> and @@ operators are special-cased by the OCaml compiler to ‘de-lambdify’ their arguments i.e. to try to full apply the functions that are passed to them, as a performance optimization. So for a lot of cases there should be no difference.


I was struggling with this as well, but I still favor pipe-first over pipe-last, just because of the „better“ type inference.

It just seems to me, that you have an easier time to map, filter, … over lists of records. Just because you don‘t have to explicitly annotate what type of record the iterating item is.

Are there other benefits to using pipe-last over pipe-first, except for performance?


You don’t necessarily need to annotate the type of the record; make sure the record is defined in some module which doesn’t contain other records with the same field names, and prefix the module name to one of the field names. This helps the compiler to place the exact record type. See Why do I need to open a module to refer to fields on one exported type?


It’s funny how I got interested on a topic that has a link to another topic where I asked a different question :smile:

By the way, is there a thread or place to discuss the data first thing? I would love to have some discussion around it.


I recommend starting by reading the debate tickets from a couple of years ago. Those of us on the t last side of the debate likely still feel a bit burnt and won’t be interested in reopening that particular wound. At least one important person exited the BuckleScript community (he still uses Reason) over it.