Skip to content

Instantly share code, notes, and snippets.

@alco
Last active August 29, 2015 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save alco/64b171db24a696786de8 to your computer and use it in GitHub Desktop.
Save alco/64b171db24a696786de8 to your computer and use it in GitHub Desktop.
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"]
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