From 557caf9adb45b7b84b1072cc603964ffbee2a9c3 Mon Sep 17 00:00:00 2001 From: Julien Richard-Foy Date: Mon, 10 Jun 2019 15:43:32 +0200 Subject: [PATCH] Update representation of un-evaluated collections as per scala/scala#8029 --- .../concrete-immutable-collection-classes.md | 4 ++-- _overviews/collections-2.13/views.md | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/_overviews/collections-2.13/concrete-immutable-collection-classes.md b/_overviews/collections-2.13/concrete-immutable-collection-classes.md index e3c8f68556..131295bf0f 100644 --- a/_overviews/collections-2.13/concrete-immutable-collection-classes.md +++ b/_overviews/collections-2.13/concrete-immutable-collection-classes.md @@ -25,7 +25,7 @@ A [LazyList](http://www.scala-lang.org/api/{{ site.scala-213-version }}/scala/co Whereas lists are constructed with the `::` operator, lazy lists are constructed with the similar-looking `#::`. Here is a simple example of a lazy list containing the integers 1, 2, and 3: scala> val lazyList = 1 #:: 2 #:: 3 #:: LazyList.empty - lazyList: scala.collection.immutable.LazyList[Int] = LazyList(?) + lazyList: scala.collection.immutable.LazyList[Int] = LazyList() The head of this lazy list is 1, and the tail of it has 2 and 3. None of the elements are printed here, though, because the list hasn’t been computed yet! Lazy lists are specified to compute lazily, and the `toString` method of a lazy list is careful not to force any extra evaluation. @@ -40,7 +40,7 @@ This function is deceptively simple. The first element of the sequence is clearl Here are the first few elements of the Fibonacci sequence starting with two ones: scala> val fibs = fibFrom(1, 1).take(7) - fibs: scala.collection.immutable.LazyList[Int] = LazyList(?) + fibs: scala.collection.immutable.LazyList[Int] = LazyList() scala> fibs.toList res9: List[Int] = List(1, 1, 2, 3, 5, 8, 13) diff --git a/_overviews/collections-2.13/views.md b/_overviews/collections-2.13/views.md index a9ec4c3d25..61ebae3cef 100644 --- a/_overviews/collections-2.13/views.md +++ b/_overviews/collections-2.13/views.md @@ -46,20 +46,20 @@ In the last statement, the expression `v map (_ + 1)` constructs a new vector wh Let's do this sequence of operations again, one by one: scala> val vv = v.view - vv: scala.collection.IndexedSeqView[Int] = View(?) + vv: scala.collection.IndexedSeqView[Int] = IndexedSeqView() The application `v.view` gives you an `IndexedSeqView[Int]`, i.e. a lazily evaluated `IndexedSeq[Int]`. Like with `LazyList`, -the `toString` operation of views does not force the view elements, that’s why the content of `vv` is shown as `View(?)`. +the `toString` operation of views does not force the view elements, that’s why the content of `vv` is shown as `IndexedSeqView()`. Applying the first `map` to the view gives: scala> vv map (_ + 1) - res13: scala.collection.IndexedSeqView[Int] = View(?) + res13: scala.collection.IndexedSeqView[Int] = IndexedSeqView() The result of the `map` is another `IndexedSeqView[Int]` value. This is in essence a wrapper that *records* the fact that a `map` with function `(_ + 1)` needs to be applied on the vector `v`. It does not apply that map until the view is forced, however. Let's now apply the second `map` to the last result. scala> res13 map (_ * 2) - res14: scala.collection.IndexedSeqView[Int] = View(?) + res14: scala.collection.IndexedSeqView[Int] = IndexedSeqView() Finally, forcing the last result gives: