3 ms·
There is another way that isn't _as_ kludgy, but still not as nice as the JavaScript proposal: computation() |> then(&Map.put(my_map, key, &1)) It's the b
by tytho 4y ago
There is another way that isn't _as_ kludgy, but still not as nice as the JavaScript proposal:
computation() |> then(&Map.put(my_map, key, &1))
It's the big reason the `then/2` function was created from my understanding.
- lvass 4y agoIt's nice in Elixir because there's a strong convention that the first argument is where you'd almost always pipe into. The JS proposal is better for retrofitting in a language.
- ollien 4y agoOh wow, TIL about `Kernel.then/2`. That definitely works around the syntax problem. An aside, the implementation is kind of amusing. It almost seems unnecessary for this to be a macro but maybe the compiler can optimize this a bit more? I would expect TCO to simplify of my "simple" implementation of def then(value, fun) do fun.(value) end https://github.com/elixir-lang/elixir/blob/a64d42f5d3cb6c32752af9d3312897e8cd5bb7ec/lib/elixir/lib/kernel.ex#L2511 https://github.com/elixir-lang/elixir/blob/a64d42f5d3cb6c327...