Logo

Programming-Idioms

History of Idiom 7 > diff from v86 to v87

Edit summary for version 87 by programming-idioms.org:
[Elixir] 404

Version 86

2020-04-24, 09:49:25

Version 87

2020-05-10, 21:54:27

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Variables
i,x,items
Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
items
|> Enum.with_index
|> Enum.each(fn({x, i}) ->
  IO.puts("#{i} => #{x}")
end)
Code
items
|> Enum.with_index
|> Enum.each(fn({x, i}) ->
  IO.puts("#{i} => #{x}")
end)
Doc URL
http://elixir-lang.org/docs/v1.0/elixir/Enum.html#with_index/1
Doc URL
https://hexdocs.pm/elixir/Enum.html#with_index/1