April 2018
Intermediate to advanced
396 pages
11h 8m
English
In the preceding section, we mentioned that it doesn't actually matter how the unit method is called. While it is true for unit and it could be propagated to any of the other methods, it is recommended that map and flatMap actually remain this way. It doesn't mean that it is not possible to make things work, but following common conventions would make things much simpler. Moreover, map and flatMap give us something extra—the possibility of using our classes in for comprehensions. Consider the following example, which is only here to illustrate how having methods with such names helps:
case class ListWrapper(list: List[Int]) { // just wrap def map[B](f: Int => B): List[B] = list.map(f) // just wrap def flatMap[B](f: ...
Read now
Unlock full access