3 ms·
As others have noted, the pipeline operator already exists in OCaml. And even if it didn't, you can define it pretty easily: let (|>) x f = f x
by thedufer 10y ago
As others have noted, the pipeline operator already exists in OCaml. And even if it didn't, you can define it pretty easily:
let (|>) x f = f x
- LeonidasXIV 10y agoCan be shortened to let (|>) x f = "%apply" which utilises some language magic and is probably faster.
- thedufer 10y agoAt risk of being pedantic, that's actually shorter. It also doesn't work, at least on the version of OCaml I'm familiar with. In order to invoke that particular bit of "language magic", you'd have to declare it external and explicitly give its type: external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply" Also, `%apply` is usually the `@@` operator. For `|>`, one would expect `%revapply`.