RosettaCodeData/Task/Associative-array-Creation/Elixir/associative-array-creation....

20 lines
452 B
Plaintext

defmodule RC do
def dict_create(dict_impl \\ Map) do
d = dict_impl.new #=> creates an empty Dict
d1 = Dict.put(d,:foo,1)
d2 = Dict.put(d1,:bar,2)
print_vals(d2)
print_vals(Dict.put(d2,:foo,3))
end
defp print_vals(d) do
IO.inspect d
Enum.each(d, fn {k,v} -> IO.puts "#{k}: #{v}" end)
end
end
IO.puts "< create Map.new >"
RC.dict_create
IO.puts "\n< create HashDict.new >"
RC.dict_create(HashDict)