Skip to content

Instantly share code, notes, and snippets.

@mudphone
Last active September 9, 2015 07:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mudphone/aad6565b18ba4cf2f45d to your computer and use it in GitHub Desktop.
Save mudphone/aad6565b18ba4cf2f45d to your computer and use it in GitHub Desktop.
Pipe Right (Thread Right `->>` from Clojure) - Pipes left-hand expression into the left-most parameter or the next function call.
defmodule CommonMacros do
defmacro left ~>> right do
[{h, _}|t] = Macro.unpipe({:|>, [], [left, right]})
:lists.foldl fn
{{_, _, args} = x, _pos}, acc ->
pos = Enum.count(args)
Macro.pipe(acc, x, pos)
{x, pos}, acc ->
Macro.pipe(acc, x, pos)
end, h, t
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment