Member-only story

Do & Don’t — Length of Range — Elixir

Malreddy Ankanna
2 min readDec 18, 2018

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

https://t.me/blackoders
if worth_clapping, do: “clap”, else: nil

🎉 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 🙏 🙏

--

--

Malreddy Ankanna
Malreddy Ankanna

Written by Malreddy Ankanna

Programmer & Writer, I write about coding, thoughts, ideas, personal musings, technical articles, and tutorials.https://bio.link/blackode

No responses yet