Member-only story
Do & Don’t — Length of Range — Elixir
Calculating the length of range
iex> range = 1..100000000
DON’T ❌
iex> range |> Enum.to_list |> length
100000000
It takes a few seconds to give you the result and it’s a bad idea.
DO ✔️
The following code statements would results in no time.
iex> range |> Enum.count
100000000
Here,Enum.count
will do pattern matching over range to extract the boundaries of the range
and perform simple arithmetic operation.
iex> min..max = range
iex> max -min + 1
100000000
Join Our Telegram Channel
🎉 Happy Coding !
Thanks Giving 🙇
Hey guys thanks for the support you have shown in reading and clapping the previous parts of this category.
Thanks 4 UR Time..
Read all parts of Killer Elixir Tips and download README.MD
file at GitHub
.
Click on the 🔗 All Killer Elixir Parts. Contribute with a 🌟
🙏 🙏 GRATITUDE 🙏 🙏