While I can see the appeal of such solutions I'd say the usual way to deal with such things is to use atoms and do the conversion on the system boundry. You convert to atom the incoming params as soon as you can, and you convert back to the integer value just before sending it out.
In general you only need two functions: to_atom/1 and from_atom/1, you can even automate generating them with a macro:
@mapping [foo: 1, bar: 2]
for {key, value} <- @mapping do
def to_atom(unquote(value)), do: unquote(atom)
def from_atom(unquote(atom)), do: unquote(value)
end
This has the huge advantage of a meaningful value for debugging and maintaining the same speed (atoms are more-or-less integers at runtime).
Michał.
> --
> You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
elixir-lang-ta...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-talk/9ff0db4b-6181-421d-8ed4-f5da8b5910d4%40googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.