Current section
Files
Jump to
Current section
Files
lib/key_sigil.ex
defmodule KeySigil do
defmacro sigil_K({:<<>>, _meta, [keys|_]}, _modifiers) do
keys
|> String.split(" ")
|> Enum.map(&String.to_atom/1)
|> Enum.reverse
|> Enum.reduce(quote(do: []), &addition/2)
end
defp addition(key, acc) do
quote bind_quoted: [acc: acc, key: key, value: Macro.var(key, nil)] do
acc |> Keyword.put(key, value)
end
end
end