RosettaCodeData/Task/Associative-array-Iteration/Elixir/associative-array-iteration...

19 lines
473 B
Plaintext

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)