A story about map

In Haskell, map is defined as:

map :: (a -> b) -> [a] -> [b]

In other typed functional languages, such as OCaml, the definition is:

List.map : ('a -> 'b) -> 'a list -> 'b list

But in Scala 2, from 2.8 through 2.12, this is the signature of map on List, as defined in the TraversableLike trait:

def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That

It returns That. What's That? Whatever CanBuildFrom decides it is.

The good news is that the collections rework in Scala 2.13 moved away from CanBuildFrom, and Scala 3, which shares the same collections library, kept the cleaner definition:

def map[B](f: A => B): List[B]

This definition overrides the more general version declared in IterableOps:

def map[B](f: A => B): CC[B]

Here, CC is the collection's type constructor.

The story doesn't end there, though. In the Scala 3.8 docs, where the library is compiled with experimental capture checking, the signature is already growing new appendages:

def map[B](f: A => B): CC[B]^{this, f}