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

18 lines
373 B
Text
Raw Permalink Normal View History

2015-11-18 06:14:39 +00:00
defmodule RC do
2016-12-05 22:15:40 +01:00
def test_create do
IO.puts "< create Map.new >"
m = Map.new #=> creates an empty Map
m1 = Map.put(m,:foo,1)
m2 = Map.put(m1,:bar,2)
print_vals(m2)
print_vals(%{m2 | foo: 3})
2015-11-18 06:14:39 +00:00
end
2016-12-05 22:15:40 +01:00
defp print_vals(m) do
IO.inspect m
Enum.each(m, fn {k,v} -> IO.puts "#{inspect k} => #{v}" end)
2015-11-18 06:14:39 +00:00
end
end
2016-12-05 22:15:40 +01:00
RC.test_create