问题:
I have a recursive function that creates objects representing file paths (the keys are paths and the values are info about the file).我有一个递归函数,它创建表示文件路径的对象(键是路径,值是关于文件的信息)。 It's recursive as it's only meant to handle files, so if a directory is encountered, the function is recursively called on the directory.它是递归的,因为它仅用于处理文件,因此如果遇到目录,则会在该目录上递归调用该函数。
All that being said, I'd like to do the equivalent of a set union on two maps (ie the "main" map updated with the values from the recursive call).话虽如此,我想在两个地图(即“主”地图更新了来自递归调用的值)上进行等价的集合并集。 Is there an idiomatic way to do this aside from iterating over one map and assigning each key, value in it to the same thing in the other map?除了迭代一个地图并将其中的每个键和值分配给另一个地图中的相同内容之外,是否有一种惯用的方法来做到这一点?
That is: given a,b
are of type map [string] *SomeObject
, and a
and b
are eventually populated, is there any way to update a
with all the values in b
?即:给a,b
的类型的map [string] *SomeObject
,以及a
和b
最终被填充,有没有什么办法来更新a
与所有的值b
?