Hi guys, maybe this is me being dense but I am str...
# arrow
r
Hi guys, maybe this is me being dense but I am struggling to find
foldLeft/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:
Copy code
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:
Copy code
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
        }