I just looked at the List::map
method declaration and was kind of perplexed by its complication. Here is how it looks:
final override def map[B, That](f: A => B)(implicit bf: CanBuildFrom[List[A], B, That]): That = {
Well, I understand what implicit
is (as far as I got, the type class based on trait CanBuildFrom
will be automatically introduced by the compiler, if in scope). But what is That
supposed to mean here?
I understand map(f: A => B)
as a functorial thing that maps each function f: A => B
to a function between corresponding monadic values List(A)
and List(B)
. So I expected to see the return type to be List[B]
.
BTW, that's what we actually have in the case of Option
.
def map[B](f: A => B): Option[B]
Both List
and Option
are monads. What's is the trick with List
?