I started scala course on coursera, but I can't get one thing here:
trait Generator[+T] { self => // do this to be able to use self instead of this def generate: T def map[S](f: T => S): Generator[S] = new Generator[S] { def generate = f(self.generate) } } Why we are using map[S] not just map in function definition?
maphas a type parameter,S.Generator[T]to anotherGenerator, not necessarely aGenerator[T], that's why you need to tell the compiler to the type you want to end up with.Generator[String]from aGenerator[Int], not justGenerator[Int]s can be returned this way. You have to refer to the new generic parameters somehow.Sand notU.