Why not just have the atom as both the argument and the value? They're little more than an integer comparison anyway.
On Tuesday, September 6, 2016 at 10:09:38 AM UTC-4, Michał Muskała wrote: > > > > On 02 Sep 2016, at 17:10, OvermindDL1 <[email protected] <javascript:>> > 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/abc4070b-fb49-4bb5-b6ea-dceb97351f59%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
