Edit : The title is a bit complex but I don’t even get how to describe this properly, so bear with me.
The thing is a python problem, which could be solved imperatively. Still, I am trying to force myself to think declaratively, and when I think experts in pattern matching, it’s here that come to mind (so I hope to get a clue when learning how to do it in elixir)
The situation is the following :
I have a first dictionnary/map (in my final case it is a DataSet from PynetDicom, but according to the documentation it is just a extended dict, so if a solution work with dict, it should do it).
This has a variable amount of field set to nil.
On the other hand I have another similar structure with all fields filed.
What I want is to fill the fields of the first with data of the second if the field name is the same.
Ex:
map1 = %{a: nil, b: nil, c:nil, d:nil}
map2 = %{c:"Hello", d:"Test", e:"Not needed"}
mapfinal = magic(map1, map2) #The thing I don't get
mapfinal = %{a:nil, b:nil, c:"Hello", d:"Test"}
In imperative, I would loop over one or both struct and if a fieldname is in the 2 of them, then struct1[“fieldname”] = struct2[“fieldname”]. But ther must be a way to do this with a tricky pattern matching.
What do you think ?
EDIT : I used the word “keyword map” which is incorrect