Logo

Programming-Idioms

History of Idiom 7 > diff from v128 to v129

Edit summary for version 129 by programming-idioms.org:
[Elixir] +DemoURL

Version 128

2022-02-19, 01:37:10

Version 129

2022-03-03, 10:24:35

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
Variables
i,x,items
Extra Keywords
indices traverse traversal
Extra Keywords
indices 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
https://hexdocs.pm/elixir/Enum.html#with_index/1
Doc URL
https://hexdocs.pm/elixir/Enum.html#with_index/1
Demo URL
https://replit.com/@ProgIdioms/AlarmingMeekFiles#main.exs