In Elixir, how can a range be converted to a list?

epotter picture epotter · Sep 16, 2014 · Viewed 13.3k times · Source

I can declare a range as follows:

range = 1..10

Is there a way to convert the range to a list?

Answer

Chris McCord picture Chris McCord · Sep 16, 2014

Enum.to_list/1 is what you're looking for:

iex(3)> Enum.to_list 1..10
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]