Jump to content

Associative array/Iteration: Difference between revisions

Added Elixir
(Added Elixir)
Line 506:
[ console write:(aKeyValue key) write:" : " writeLine:aKeyValue ].
].</lang>
 
=={{header|Elixir}}==
<lang elixir>defmodule RC do
def test_iterate(dict_impl \\ Map) do
d = dict_impl.new |> Dict.put(:foo,1) |> Dict.put(:bar,2)
print_vals(d)
end
defp print_vals(d) do
IO.inspect d
Enum.each(d, fn {k,v} -> IO.puts "#{k}: #{v}" end)
Enum.each(Dict.keys(d), fn key -> IO.inspect key end)
Enum.each(Dict.values(d), fn value -> IO.inspect value end)
end
end
 
IO.puts "< iterate Map >"
RC.test_iterate
IO.puts "\n< iterate HashDict >"
RC.test_iterate(HashDict)</lang>
 
{{out}}
<pre>
< iterate Map >
%{bar: 2, foo: 1}
bar: 2
foo: 1
:bar
:foo
2
1
 
< iterate HashDict >
#HashDict<[foo: 1, bar: 2]>
foo: 1
bar: 2
:foo
:bar
1
2
</pre>
 
=={{header|Erlang}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.