Reputation: 1
I want to aggregate KTable entries to a Map of Sets (e.g. Map<Set<String>>
), so in the aggregate function I need to provide adder
and subtractor
, which look like this:
(key, value, map) -> {
map.computeIfAbsent(key, k -> new HashSet<>()).add(value);
return map;
},
(key, value, map) -> {
map.computeIfAbsent(key, k -> new HashSet<>()).remove(value)
return map;
}
My question is: Is it OK to return the map as is, or should the aggregator be an immutable object, which force me to deep clone the entire map of sets on every call?
Upvotes: 0
Views: 33
Reputation: 62285
It should be ok to modify the passed in aggregate
parameter (ie, your map
). There should be no need to deep-copy it.
Upvotes: 0