Hacker News new | ask | show | jobs
by mdemare 297 days ago
One of the things I dislike about function notation is that in f(g(h())) execution order is right-to-left. I like OO partly because execution order is writing order ( h().g().f() )

In Clojure I love the threading macro which accomplishes the same: (-> (h) (g) (f))

2 comments

In Haskell there's also dot (edit - my bad, not dot, pipe) syntax which allows composing functions left to right. I believe Nim also has it. Just as a few more examples.
f . g is still doing g first, then f, right? Haskell has pipelines in the Flow library.

https://hackage-content.haskell.org/package/flow-2.0.0.9/doc...

No need to import a third party library: you can use `Data.Function ((&))` for this:

    arg
     & f1
     & f2
     & f3
Ooops my bad. Been too long.
I don’t think that’s correct. The dot operator is composition with the same semantics as when using normal math notation.

   (f . g) x
is equivalent to

   f (g x)
Nim and other languages addressed that by making . akin to a pipe operator. It takes the left and sends it to the right, as the first argument