I was reading through some code and came across this line:
|> Kernel.||(build_conn_forward_path(conn, router, path))
What do the double vertical bars mean?
I was reading through some code and came across this line:
|> Kernel.||(build_conn_forward_path(conn, router, path))
What do the double vertical bars mean?
That is a function call to the kernel function Kernel.||/2
(docs). Which is the short-circuiting OR.
It’ll probably look more familiar as: some_val || build_conn_forward_path(conn, router, path)
Generally using that kernel function in a pipeline would be an overuse of the pipe operator.
I wrote most of what @axelson already supplied, and not as well. To his advice, I’ll add that the ||
has no special unique significance here - it’s not describing something you might see the vertical pipe character used for in another language, just naming an existing special-form macro.
One way to write this more idiomatically would be to write that step as a new private function with multiple function bodies, where the function head pattern-matches on whether its first argument was nil
or not. This would be more pipeline-friendly as well as possibly better at expressing the human intent.
At a bare minimum you could just apply that test in the preceding call, e.g.
Apparent approach:
...
|> function()
|> Kernel.||(other_function())
Minimally different but still somewhat better:
...
|> function() || other_function()
...
|> function() || other_function()
I would not recommend this. It is tempting to pipe even more:
...
|> function() || other_function()
|> third_function()
And that most likely is not what the programmer intend to do.
I don’t disagree!