Reputation: 4415
I have a map of items to process:
fun processAll(items: Map<Int, CustomObject>) {
items.forEach {
process(anotherSet[it.key])
}
}
What I want to do is for keys that were not processed i.e. the anotherSet
has keys that were not part of the items
I would like to
call another method to do something with those.
How can I do this in a Kotlin specific way?
Upvotes: 0
Views: 1885
Reputation: 23144
I suppose anotherSet
is actually a Map
, given how you use it. Then you can get the residual map from it by subtracting all the keys that are contained in the items
map:
val remaining = anotherSet - items.keys
for ((key, value) in remaining) {
...
}
You can play with the runnable example here: https://pl.kotl.in/DQVanLYrp
Upvotes: 3