Enum.all-question-mark
You're seeing just the function
all-question-mark
, go back to Enum module for more information.
Specs
Returns true
if all elements in enumerable
are truthy.
When an element has a falsy value (false
or nil
) iteration stops immediately
and false
is returned. In all other cases true
is returned.
Examples
iex> Enum.all?([1, 2, 3])
true
iex> Enum.all?([1, nil, 3])
false
iex> Enum.all?([])
true
Specs
all?(t(), (element() -> as_boolean(term()))) :: boolean()
Returns true
if fun.(element)
is truthy for all elements in enumerable
.
Iterates over enumerable
and invokes fun
on each element. If fun
ever
returns a falsy value (false
or nil
), iteration stops immediately and
false
is returned. Otherwise, true
is returned.
Examples
iex> Enum.all?([2, 4, 6], fn x -> rem(x, 2) == 0 end)
true
iex> Enum.all?([2, 3, 4], fn x -> rem(x, 2) == 0 end)
false
iex> Enum.all?([], fn _ -> nil end)
true
As the last example shows, Enum.all?/2
returns true
if enumerable
is
empty, regardless of fun
. In an empty enumerable there is no element for
which fun
returns a falsy value, so the result must be true
. This is a
well-defined logical argument for empty collections.