Last active
September 9, 2015 07:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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