Skip to content

Update representation of un-evaluated collections as per scala/scala#8029 #1358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(<not computed>)

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.
Expand All @@ -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(<not computed>)
scala> fibs.toList
res9: List[Int] = List(1, 1, 2, 3, 5, 8, 13)

Expand Down
8 changes: 4 additions & 4 deletions _overviews/collections-2.13/views.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(<not computed>)

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(<not computed>)`.

Applying the first `map` to the view gives:

scala> vv map (_ + 1)
res13: scala.collection.IndexedSeqView[Int] = View(?)
res13: scala.collection.IndexedSeqView[Int] = IndexedSeqView(<not computed>)

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(<not computed>)

Finally, forcing the last result gives:

Expand Down