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 方法理解为一个集合取值时的懒加载行为。
defview: TraversableView[A, Repr]
demo
// create a large numeric range and take the first 10 odd numbersscala>val largeOddNumberList: List[Int] = (1 to 1000000).filter(_ %2!=0).take(10).toListlargeOddNumberList: 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 numbersscala>val lazyLargeOddNumberList = (1 to 1000000).view.filter(_ %2!=0).take(10).toListlazyLargeOddNumberList: List[Int] = List(1, 3, 5, 7, 9, 11, 13, 15, 17, 19)