Can't figure out how to nest Enum.map inside of other Enum.map

Seems you’re looking for Enum.flat_map.

…or the power of for comprehensions.

parsed_data = [
  %{
    count: 1000000000,
    postal_code: ["92887", "92886"],
    state: "California",
  },
  %{
    count: 1000000000,
    postal_code: ["97206", "97205"],
    state: "Texas",
  }
]

for item <- parsed_data, code <- item.postal_code do
  %{count: item.count, postal_code: code, state: item.state}
end

[
  %{count: 1000000000, postal_code: "92887", state: "California"},
  %{count: 1000000000, postal_code: "92886", state: "California"},
  %{count: 1000000000, postal_code: "97206", state: "Texas"},
  %{count: 1000000000, postal_code: "97205", state: "Texas"}
]
3 Likes