4 ms·
I played a little with Elixir (and Phoenix) months ago and I know the |> operator, which is not exactly what I was looking for in my reply. I'll look again at E
by pmontra 12y ago
I played a little with Elixir (and Phoenix) months ago and I know the |> operator, which is not exactly what I was looking for in my reply. I'll look again at Elixir and at how it handles callbacks.
- tel 12y ago|> is (not, see below) mere function composition function compose(f, g) { return function inner(x) { return f(g(x)); } } this is not the right kind of composition for something like nested callbacks. For that you need slightly more. Edit: It's actually the "apply" operator which looks like function apply(f) { return function applied(x) { return f(x); } } Apply and compose work together nicely. For instance, in Haskell apply is ($) and compose is (.), so you can build a compositional pipeline and apply it like f . g . h $ x or like f $ g $ h $ x since association goes this way f $ (g $ (h $ x))
- deleted 12y ago[deleted]
- tel 12y agoAh, my bad, I was distracted writing. It's Haskell's ($), not the (.).
- rubiquity 12y agoNo worries. I deleted my post before your reply came through because I didn't feel my example was good and I'm struggling to do better this early in the morning :D In a lot of cases compose and |> will be similar due to operations that are commutative, but they are semantically different.
- rubiquity 12y agoThere aren't any callbacks in Elixir. The run time takes care of scheduling for you. The code you write looks synchronous but is executing asynchronously.
- phamilton 12y agoNot only does this make your code easier to read, it also means that the entire ecosystem is available to you rather than a partitioned between sync and async libraries.
- phamilton 12y agoNot only does this make your code easier to read, it also means that the entire ecosystem is available to you rather than a partitioned between sync and async libraries.