An Elixir Version of Rails’ returning

A few days ago I was writing some code where just about every function ended

def func1 do
  # really cool code…
  result = do_some_calculation(...)
  Logger.info "func1 → #{result}
  result
end

(OK, so the actual code was more compelling than this).

I hated the use of the temporary result variable, so ended up writing an implementation of the Ruby on Rails returning method. The resulting macro was so concise and (I think) elegant, I thought I’d share:

Please keep it clean, respectful, and relevant. I reserve the right to remove comments I don't feel belong.
  • NickName, E-Mail, and Website are optional. If you supply an e-mail, we'll notify you of activity on this thread.
  • You can use Markdown in your comment (and preview it using the magnifying glass icon in the bottom toolbar).