Is there any benefit of converting a List to a LazyList in Scala?

61 Views Asked by At

Is there any gain from converting a List to a LazyList in Scala?

For example:

val x = Seq(1, 2, 3, 4, 5)

// This is supposed to save more memory in the long term
val y = x.to(LazyList)

A colleague I work with says that it reduces the amount of memory being used.

However, in my mind, the List is already loaded into memory. Doesn't that mean all the values have already been computed?

0

There are 0 best solutions below