Anyone know of a collection version of `Map<K, ...
# codereview
d
Anyone know of a collection version of
Map<K, V>.putIfAbsent(key: K, value: V)
?
putAll
overrides existing values sadly.
s
Would you mind clarifying what you mean by a “collection version?”
oh, I see, you want
putIfAbsent(other: Map<K, V>)
d
I guess something like
Map<K, V>.putIfAbsent(other: Map<K, V>)
?
lol
yeah
s
you could just reverse the order of
putAll
, couldn’t you?
d
Hmmm, if both were mutable.
I guess I need
MutableMap<K, V>.putIfAbsent(other: Map<K, V>)
😅 .
s
you could maybe use
+
in the preferred order?
d
I need to do it multiple times to build a big map. I'd have to use
var
😅.
s
gotcha
here’s a somewhat cursed idea - what if you
fold
over a collection of all your maps
or maybe
reduce
into a mutableMap or something
d
I'm more or less doing that already. I might be trying to hard to shrink this code.
Am I trying too hard?
s
¯\_(ツ)_/¯ hm
I couldn’t tell you from a quick glance, being entirely honest
d
Ha okay. Thanks for helping anyway!
👍 1