Hey, I am reading programmng in scala 4 edition and I found section
“Handling strictness”
I have trouble understanding meaning of
The collection framework’s template traits, therefore, must support both
strict and non-strict evaluation, and allow concrete collection types that ex-
tend the template traits to determine strictness. For instance, the default im-
plementation of map needs to be strict when inherited by List , but non-strict
when inherited by View
also there are 3 traits, what new View.Map(this, f) mean in IterableOps? It looks like instance of abstract trait with map applicated to it except that it dont define iterator
trait IterableOps[+A, +CC[_], +C] {
def filter(p: A => Boolean): C
def map[B](f: A => B): CC[B]
}
trait View[+A]
extends Iterable[A]
with IterableOps[A, View, View[A]] {
def iterator: Iterator[A]
}
trait IterableOps[+A, +CC[_], +C] {
def filter(pred: A => Boolean): C =
fromSpecific(new View.Filter(this, pred))
def map[B](f: A => B): CC[B] =
from(new View.Map(this, f))
protected def fromSpecific(source: IterableOnce[A]): C
protected def from[E](source: IterableOnce[E]): CC[E]
}