-
-
Save dgoldie/557cd3da8172307b0ad6 to your computer and use it in GitHub Desktop.
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
import M | |
File.read("match.exs") |> match({:ok, bin}, bin) |> String.length | |
#=> 156 | |
s = """ | |
id;name;value | |
1;foo;hi | |
2;bar;bye | |
""" | |
s | |
|> String.strip | |
|> String.split("\n") | |
|> Enum.map(&String.split(&1, ";")) | |
|> Enum.map(&match(&1, [_,name,_], name)) | |
#=> ["name", "foo", "bar"] |
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 M do | |
defmacro match(thing, pattern, selector) do | |
quote do | |
unquote(pattern) = unquote(thing) | |
unquote(selector) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment