Associative array/Iteration: Difference between revisions
Content added Content deleted
(→{{header|Babel}}: Updated to interactive-mode syntax) |
(→{{header|Elixir}}: remove deprecated module (Dict, HashDict), and then simplify) |
||
Line 725: | Line 725: | ||
=={{header|Elixir}}== |
=={{header|Elixir}}== |
||
<lang elixir> |
<lang elixir>IO.inspect d = Map.new([foo: 1, bar: 2, baz: 3]) |
||
⚫ | |||
def test_iterate(dict_impl \\ Map) do |
|||
⚫ | |||
d = dict_impl.new |> Dict.put(:foo,1) |> Dict.put(:bar,2) |
|||
⚫ | |||
print_vals(d) |
|||
Enum.each(Map.values(d), fn value -> IO.inspect value end)</lang> |
|||
end |
|||
defp print_vals(d) do |
|||
IO.inspect d |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
end |
|||
IO.puts "< iterate Map >" |
|||
RC.test_iterate |
|||
IO.puts "\n< iterate HashDict >" |
|||
RC.test_iterate(HashDict)</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
%{bar: 2, baz: 3, foo: 1} |
|||
< iterate Map > |
|||
{:bar, 2} |
|||
{:baz, 3} |
|||
⚫ | |||
{:foo, 1} |
|||
⚫ | |||
:baz => 3 |
|||
⚫ | |||
:bar |
:bar |
||
:baz |
|||
:foo |
:foo |
||
2 |
2 |
||
3 |
|||
1 |
1 |
||
< iterate HashDict > |
|||
#HashDict<[foo: 1, bar: 2]> |
|||
⚫ | |||
bar: 2 |
|||
:foo |
|||
:bar |
|||
1 |
|||
2 |
|||
</pre> |
</pre> |
||