fork download
  1. defmodule Main do
  2. def traverse(name \\ "", struct)
  3. def traverse(root, map) when is_map(map), do: Enum.each(map, fn {key, value} -> traverse("#{root}.#{key}", value) end)
  4. def traverse(key, value), do: IO.puts "#{key} --> #{value}"
  5.  
  6. def main do
  7. traverse(%{a: 1, b: %{c: 2, d: %{e: 3, f: 4}}})
  8. end
  9. end
  10.  
  11. Main.main
  12.  
Success #stdin #stdout 0.22s 2115584KB
stdin
Standard input is empty
stdout
.a --> 1
.b.c --> 2
.b.d.e --> 3
.b.d.f --> 4