Skip to content
Snippets Groups Projects
Select Git revision
  • e9352f78e459a0b4cd2f5adfb650425f5c3f84cd
  • main default protected
2 results

scanRightExample.worksheet.sc

Blame
  • 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)))