Skip to content

Instantly share code, notes, and snippets.

@Papipo
Created June 8, 2015 18:33
Show Gist options
  • Select an option

  • Save Papipo/008d9d8387d943208c46 to your computer and use it in GitHub Desktop.

Select an option

Save Papipo/008d9d8387d943208c46 to your computer and use it in GitHub Desktop.
defmacro whitelist_literals(literals) do
quote do
for literal <- unquote(literals) do
case literal do
:boolean -> defp allow(exp) when is_boolean(exp), do: exp
:number -> defp allow(exp) when is_number(exp), do: exp
:integer -> defp allow(exp) when is_integer(exp), do: exp
:float -> defp allow(exp) when is_float(exp), do: exp
:tuple -> defp allow(exp) when is_tuple(exp), do: exp
:list -> defp allow(exp) when is_list(exp), do: exp
:map -> defp allow(exp) when is_map(exp), do: exp
unknown -> raise "Unknown literal #{inspect unknown}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment