Home »
Code Examples »
Scala Code Examples
Scala - How to use scan method? Code Example
The code for How to use scan method?
object Demo {
def main(args: Array[String]) = {
val nums = List(10, 20, 30, 40)
//apply operation to create a running
//total of all elements of the list
val result = nums.scan(0)(_ + _)
//print result
println(result)
}
}
/*
Output:
List(0, 10, 30, 60, 100)
*/
Code by IncludeHelp,
on August 13, 2022 20:41