This was not what I meant. If I need a scan function, I would implement it like this:
fun <A, B> Sequence<A>.scanLeft(f: (B, A) -> B, z: B): Sequence<B> = generate<B> {
var acc = z
for (a in this@scanLeft) {
acc = f(acc, a)
yield(acc)
}
}
But this is not what I need. It was only an example. What I would need is a way to abstract what is common in many problems about collection such as mapping, filtering, concatenating, scanning, etc. And this abstraction is folding. So lazy collections needs lazy folding.