You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have a map of nested maps, because I have recently struggled myself with a query, I'd like to show you how you can update each of the nested maps in a consistent fashion, using multiple approaches. Your input, a single map, may resemble the following:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
If you have a map of nested maps, because I have recently struggled myself with a query, I'd like to show you how you can update each of the nested maps in a consistent fashion, using multiple approaches. Your input, a single map, may resemble the following:
Say you want to add one or several properties to each of the maps (keyed
apple
,potato
andacorn
), the shortest expression is probably something like:Approach 1
With the above, the map expressed with
{ "planet": "Earth", "season": "fall" }
is merged with every nested map (bound to.
insidewith_entries
):Approach 1.1
There's at least one variation on the above that produces equivalent result:
Approach 1.2
The above, can be further shortened to:
The way I understand it,
with_entries
is implemented in a manner where it's equivalent to:Approach 2
Remember the importance of operator precedence rules, assuming you only wanted to add one of the properties,
planet
, the below snippet will not yield the expected result:On the other hand, the following amendment on the above does work:
I hope all this is useful to someone.
Beta Was this translation helpful? Give feedback.
All reactions