2 ms·
Are they, though? The relevant functions in Enum all seem to be zero-based, for example: iex> [:foo, :bar, :baz] |> Enum.at(1) :bar Not that it reall
by yellowapple 8y ago
Are they, though? The relevant functions in Enum all seem to be zero-based, for example:
iex> [:foo, :bar, :baz] |> Enum.at(1)
:bar
Not that it really matters anyway. Like with Erlang, in the vast majority of cases where I'd normally reach for querying a list element by index, pattern matching is the better / more idiomatic option. Compare:
foo = list |> Enum.at(0)
bar = list |> Enum.at(1)
baz = list |> Enum.at(2)
rem = list |> Enum.slice(3..-1)
with:
[foo, bar, baz | rem] = list
Both give you the exact same values of foo/bar/baz/rem, but the latter is arguably more readable and concise, and entirely avoids the 0 v. 1 debate.