The reason for the error you get is that on the second line of your code, you attempt to fill some value into a.items2. However, it is impossible to do structure.property = new_value in Elixir. Rather,
def main_loop(items) do
Enum.map(items, &alter_item/1)
end
def alter_item(item = %{items2: nested_items) do
new_nested_items = Enum.map(nested_items, &alter_nested_item/1)
%{item | items2: new_nested_items}
end
def alter_nested_item(nested_item) do
Map.put(nested_item, :new_value, 123)
end
Note that because of how this is split up in separate functions, the put_in becomes superfluous since pattern matching is used.