I have a list of addresses and I need to fix the records, some of the records have the house number as a range and I need to split it into multiple records. How would I enumerate over the list and fix/duplicate the records?
defmodule EnumTesting do
def list_stuff() do
list = [ %{street: "street", nr: "2" }, %{street: "street", nr: "4" }, %{street: "street", nr: "6-10" } ]
list |> Enum.filter(&needs_fixing?(&1))
end
defp needs_fixing?(item) do
String.contains?(item.nr, "-")
end
end
Expected result:
[ %{street: "street", nr: "2" }, %{street: "street", nr: "4" }, %{street: "street", nr: "6" }, %{street: "street", nr: "8" }, %{street: "street", nr: "10" } ]
7
and9
? – Dogbert