> On 02 Sep 2016, at 17:10, OvermindDL1 <[email protected]> wrote:
> 
> Yeah that macro would be quite useful.  This Const I would use on such 
> bounds, I just hate magic numbers in the code even at the bounds, hence 
> helper methods.

I fully agree with that, the way I would handle that is with some macros to 
generate the conversion functions:

statuses = [draft: 0, pending: 1, complete: 2, published: 3]

for {atom, int} <- statuses do
  def to_status(unquote(int)), do: unquote(atom)
  def from_status(unquote(atom)), do: unquote(int)
end

This gives you two functions and no free-floating magic numbers.

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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-talk/8307344C-9F26-4281-B0D2-99B113B0AD79%40muskala.eu.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to