Conditional pipe operator on error tuple

I wanted to share this code for a problem that regularly comes up and that I usually solve with multi-headed functions or with clauses. The issue: handling an error tuple in a pipeline situation by skipping steps.

Here’s the code: (Important: There’s a bug in this macro, see below)

  defmacro left ~> right do
    quote do
      case unquote( left ) do
        { :error, _ } = err -> err
        val -> unquote( Macro.pipe( left, right, 0 ) )
      end
    end
  end

Which makes possible a pipeline that looks like:

start_value
|> step_a
~> step_b
~> step_c
|> step that handles  { :error, _ } or a real result

Any thoughts on this approach?

Dan