I'm confused about what is going on with the following code. task.yield is a hashmap from a to b, and store.put is a suspend function which takes an a and a b. The first way of iterating thru the map works with no issue, as does the second. The third way, which feels to me like the most natural way to do the iteration and was what I wrote initially, causes kotlin to complain that suspend functions can be called only within a coroutine body. I'm guessing this has to do with how forEaching on a map works (as opposed to a list maybe?) but I don't really understand what the issue is.
launch{
// Kotlin is perfectly happy with this
for(elt in task.yield.keys){
store.put(elt,task.yield[elt]!!)
}
// and this
task.yield.keys.forEach {
store.put(it,task.yield[it]!!)
}
// This makes kotlin sad. I'm not sure why
task.yield.forEach { t, u ->
store.put(t, u)
}
}
Edit: I've just noticed that the list forEach is an inline function while the map one I'm trying to use isn't. I'm guessing this is the issue.