Can elixir make optimisations of Enum.count automatically?

Quick question!

If you have code like this
if Enum.count(x) > 1 do .... end

Can elixir optimise the line, and exit the count as soon as more than one element exists?
Is it worth me writing my own function for this? or is there a function that does this instead?
something like Enum.more_than(x, 1)

Thank you!

No.

Enum.count_until can do that.

4 Likes

If you create an issue in Tria optimizing compiler with this feature, I’ll implement it.

4 Likes

Legend! :slight_smile:

p.s, Im read through that repo, honestly insane how good some people are

Ok, didnt think it would to be honest, but you never know with some langs.