I am trying to write my own generic map
function and following is what I have come up with:
def map[A, B, CC[X] <: Traversable[X], That]
(xs: CC[A])(f: A => B)
(implicit cbf: CanBuildFrom[CC[_], B, That]): That = {
val b = cbf(xs)
for (a <- xs)
b += f(a)
b.result
}
This seems to work with List
, Vector
, but not with the Map
s. What changes should I make so that it works with Map
s too?