Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is_integer() doesn't work with Enum.all?

Tags:

elixir

Total Elixir noob here. Here's my question:

When using the Enum.all?/2 function, we pass a function as the second argument:

iex(19)> is_int = &(is_integer(&1))
iex(20)> Enum.all?(list, is_int)
true

Why is it, then, that I can't pass is_integer directly?

iex(21)> Enum.all?(list, is_integer)
** (CompileError) iex:21: undefined function is_integer/0
    (stdlib) lists.erl:1354: :lists.mapfoldl/3
    (stdlib) lists.erl:1355: :lists.mapfoldl/3

Is is_integer not a function? It looks like that from the error. What is the mapfoldl we see there?

like image 930
ankush981 Avatar asked Feb 17 '26 14:02

ankush981


1 Answers

You have to capture this function. Use:

Enum.all?(list, &(is_integer(&1))
like image 64
PatNowak Avatar answered Feb 21 '26 15:02

PatNowak