rawtoast
04/14/2018, 6:49 PMfoldLeft/Right
methods for a map. The only one intellij suggests to me (in MapK.kt) looks like it is for folding a map into another map and isn’t the generic method I would’ve expected:
fun <K, A, B> Map<K, A>.foldLeft(b: Map<K, B>, f: (Map<K, B>, Map.Entry<K, A>) -> Map<K, B>): Map<K, B> {
var result = b
this.forEach { result = f(result, it) }
return result
}
I would’ve thought the method signature for a standard foldLeft would instead look like this:
fun <K, A, B> Map<K, A>.foldLeft(b: B, f: (B, Map.Entry<K, A>) -> B): B {
var result = b
this.forEach { result = f(result, it) }
return result
}