Why not both?
So as an example of doing both, consider following Java pseudocode (simples example that comes to my mind now):
Foo value = someCondition()
? map1.computeIfAbsent("key", defaultValueProvider)
: map2.computeIfAbsent("key", defaultValueProvider);
This both gets a value and changes state of the map; which map is queried/altered is determined by the condition. I personally don't mind such code, and prefer it to if/else version. Foo value = ( someCondition() ? map1 : map2 ).computeIfAbsent("key", defaultValueProvider);
Or some kind of moral equivalent?For clarity, let's rewrite it as:
Foo value = someCondition()
? map1.computeIfAbsent("key", defaultValueProvider)
: list1.get(42);