elixir-lang/elixir — pull request #2921 by lstor (2014-12-05 14:45:46+00:00)
Title: Add implementation of Integer.undigits

Implements `Integer.undigits`, which is the counterpart to `Integer.digits`.

I made two different implementations. The first one (4d43155) uses `Enum.reverse/1` and is a bit neater, but I'm not sure if we want to depend on the `Enum` module here?

The second option (edc0a0c) constructs the number in natural ordering, and then uses `pow` to give it the correct value. I believe this is slightly more efficient than the `reverse` option, but the code is less clean.

Which alternative do we want?

A few more things:

- Is there a nicer way to ensure the result is an integer, than using `:erlang.trunc/1`?
- Is there a way to use guards to ensure the input list consists of integers only? (I presume not.) Should we handle it in any way, or take the happy path?
- If we decide to go for the non-`reverse` option, I will test it more thoroughly to ensure correct behavior for all kinds of input. I'm currently more confident in the `reverse` implementation.
- The implementations support [Signed-digit representation](http://en.wikipedia.org/wiki/Signed-digit_representation), which is intentional. Doing anything else would be less efficient.

Any other input or feedback is of course welcome too.