6 ms·
Elixir/Unix style pipe operations in Ruby! https://github.com/LendingHome/pipe_operator https://github.com/LendingHome/pipe_operator
by bonquesha99 8y ago
Elixir/Unix style pipe operations in Ruby!
https://github.com/LendingHome/pipe_operator https://github.com/LendingHome/pipe_operator
- dnautics 8y agoit's not nearly the same. Piping in elixir is a macro; it lets you preserve the other arguments in your function call. The IO.inspect(value, label: "label string") semantic is incredibly powerful. During debugging I often do this: value |> IO.inspect(label: "A") |> do_something |> IO.inspect(label: "B") |> do_something_else |> IO.inspect(label: "C") ... This gives me full visibility over the data transformations that are happening. And removing the IO.inspect's are trivial with an IDE like atom, vscode, etc. Also the way that the BEAM handles concurrent IO means that none of those strings that I send will be interrupted by other content, which is critical to interpretable println debugging in a concurrent environment. I haven't used the debugger (or IEX.pry, whic I hear is powerful) once.
- bonquesha99 8y agoThat's what it's doing, arguments are preserved: # don't really know what IO.inspect is doing # but guessing something like this? def IO.inspect(value, label:) puts "#{label}: #{value.inspect}" value end value.pipe do IO.inspect(label: "A") do_something IO.inspect(label: "B") do_something_else IO.inspect(label: "C") end
- dnautics 8y agooh I didn't get past "Matz on Ruby"! Sorry. I do think the native pipe operator is prettier.