Scala: why can't I map a function accepting Seq[Char] over a collection of Strings

Viewed 769

I can define a function that accepts a Seq[Char]

def f(s: Seq[Char]) = s

and it works if I pass in a String:

scala> f("this")
res8: Seq[Char] = this

which means that I can use it in a map:

scala> List("this").map(s => f(s))
res9: List[Seq[Char]] = List(this)

So why can't I do this?:

scala> List("this").map(f)
<console>:10: error: type mismatch;
 found   : Seq[Char] => Seq[Char]
 required: java.lang.String => ?
              List("this").map(f)
                               ^
2 Answers
Related