At startup
1..10000000000000000000 |> Enum.sum
The result is calculated as constant time - I assume that it uses the formula 1+ 2+ ... + n = n(n+1) / 2
What allows the elixir to do this optimization? is a 1..n symbol other than the declaration of a regular list as [1,2,3]. When I check 1..100000, it returns a string. What's going on here?
source
share