Skip to content

Instantly share code, notes, and snippets.

@odo
Last active June 1, 2016 15:40
Show Gist options
  • Save odo/50c82b7ca65a67025c30 to your computer and use it in GitHub Desktop.
Save odo/50c82b7ca65a67025c30 to your computer and use it in GitHub Desktop.
Elixir macro to bind variables inside pipes (experimental)
defmodule BindInPipes do
defmacro bind(state, variable) do
ast = quote do
{:__block__, [], [
{:=, [], [{:var!, [context: Elixir, import: Kernel], [{unquote(variable), [], Elixir}]}, unquote(state)]},
unquote(state)
]}
end
{result, []} = Code.eval_quoted(ast, [], __ENV__)
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment