The view method will create a non-strict version of the collection which means that the elements of the collection will only be made available at access time.
可以将view 方法理解为一个集合取值时的懒加载行为。
def view: TraversableView[A, Repr]
demo
// create a large numeric range and take the first 10 odd numbers
scala> val largeOddNumberList: List[Int] = (1 to 1000000).filter(_ % 2 != 0).take(10).toList
largeOddNumberList: List[Int] = List(1, 3, 5, 7, 9, 11, 13, 15, 17, 19)
// lazily create a large numeric range and take the first 10 odd numbers
scala> val lazyLargeOddNumberList = (1 to 1000000).view.filter(_ % 2 != 0).take(10).toList
lazyLargeOddNumberList: List[Int] = List(1, 3, 5, 7, 9, 11, 13, 15, 17, 19)