Is there a function composition operator in reason?


Is there operators similar to >> or << from elm-lang or . of haskell




Not exactly. Point-free style is not considered idiomatic in Reason/OCaml as it is in Haskell. There are a couple of operators which can compose functions and apply an argument at the same time:


well the problem with those is that you need to provide the parameter upfront but what I would like to do out of box is [1,2,3] (((+)5)>>String.fromInt)

In the elm code above I didnt have to write a closure to be able to pass the variable around I simply composed a new function from simpler functions.


I created the following

let (>>) = (a: 'a => 'b, b: 'b => 'c): ('a => 'c) => {
  let helper = vl => vl->a->b;

Is there any way to do this whithout the helper function in there?


IMHO, this is quite difficult to follow. I would this much easier to read: => String.fromInt(n + 5), [1, 2, 3])

And it’s just a few more characters. Or if you want to pipe everything, maybe even: => n |> (+)(5) |> String.fromInt, [1, 2, 3])

But really it doesn’t gain you much.