One of the things I love about programming in dialects of ML like ocaml and f# is the forward pipe operator:
x
|> f
|> g
|> h
It's nice because it just puts whatever's on the left of the operator in as the last argument. So it also works for functions with an arity of more than one.
So if it were something like
h(z, g(y, f(x))
you can write it as
x
|> f
|> g y
|> h z
It works really nicely for data munging code:
my_data
|> filter (x => x > 37)
|> select (x => x * 2)
|> sum
but unlike doing it with method calls in object oriented code, inserting a new function into the chain doesn't involve modifying a class or or mucking around with more complex language features like extension methods and traits.
So if it were something like
you can write it as It works really nicely for data munging code: but unlike doing it with method calls in object oriented code, inserting a new function into the chain doesn't involve modifying a class or or mucking around with more complex language features like extension methods and traits.