Select Git revision
scanRightExample.worksheet.sc
scanRightExample.worksheet.sc 411 B
// From https://stackoverflow.com/questions/17408880/reduce-fold-or-scan-left-right
val abc = List("A", "B", "C")
def add(res: String, x: String) = {
res + x
}
println(abc.scanLeft("z")(add))
println(abc.scanRight("z")(add))
val funcs = List(
(x: Int) => x + 1,
(x: Int) => x * 2,
(x: Int) => x * x
)
println(funcs.scanLeft(2)((v, f) => f(v)))
println(funcs.reverse.scanLeft(2)((v, f) => f(v)))