I probably miss something very obvious: how to efficiently filter and iterate over entries in the HashMap in Kotlin?
I want to do the following:
myMap.filterValues{ someCondition }.forEach { doSomethingWithTheEntry }
How can I avoid creating intermediate objects? filterValues will create a HashMap that is not needed here.
I could certainly write
myMap.forEach { if(someCondition) doSomethingWithTheEntry }
but the filter style approach with a functional style looks more elegant.
source
share