Transform through a view and force a small result.

Lazy Views

LazyView.scala
object Main {
  def main(args: Array[String]): Unit = {
    val factor = 
    val nums = List(1, 2, 3, 4)
    val scaled = nums.view.map(n => n * factor).take(2).toList

    println("result=" + scaled.mkString(","))
    println("count=" + scaled.length)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val factor = 
    val nums = List(1, 2, 3, 4)
    val scaled = nums.view.map(n => n * factor).take(2).toList

    println("result=" + scaled.mkString(","))
    println("count=" + scaled.length)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val factor = 
    val nums = List(1, 2, 3, 4)
    val scaled = nums.view.map(n => n * factor).take(2).toList

    println("result=" + scaled.mkString(","))
    println("count=" + scaled.length)
  }
}
lazy-view A `view` delays work until the result is needed. Calling `toList` forces only the elements that are kept, here the first two scaled numbers.