var t = 0
fun sumIntMap(hm: HashMap<Int,Int>) = hm.forEach{ x -> t+=x.value
}.let { t }
Trying to sum a Hashmap Int values here with a function, I cannot seem to optimize it so that it requires not capturing and needing the temp var (t).
How can I use temp vars in lambdas and return them? Is how I wrote it the only real way (using a let to return the temp var)?
Thanks!