Created
November 20, 2015 02:09
-
-
Save killme2008/cc1c5b38740bfa775acc to your computer and use it in GitHub Desktop.
Clojure thread macro '->>' in elixir
This file contains hidden or 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 Pipe do | |
defmacro a|>b do | |
pos = tuple_size(b) -1 | |
Macro.pipe(a, b, pos) | |
end | |
defmacro __using__(_extras) do | |
quote do | |
import Kernel, except: [|>: 2] | |
import Pipe | |
end | |
end | |
def map(f, c) do | |
Enum.map(c, f) | |
end | |
def join(sep, c) do | |
Enum.join(c, sep) | |
end | |
end | |
defmodule Test do | |
use Pipe | |
IO.puts ([1,2,3] |> map(&(&1+1)) |> join(" ")) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment