Scala streams evaluation

Viewed 391

Suppose I have this code

val stream = Stream.continually(1)
val s = stream.take(10).map(i => {
  throw new RuntimeException
  i
})

As far as I understand, the function passed to map is evaluated when the corresponding element in stream s is accessed. If s is never iterated and no element is ever accessed, why does the exception get thrown?

2 Answers
Related