I was browsing around and found a question about grouping a String
by it\'s characters, such as this:
The input:
\"aaabbbccccdd\"
>
Whenever you try to use methods such as groupBy
on the String. It's important to note that it is implicitly converted to StringOps and not List[Char].
The signature of groupBy
is given by-
def groupBy[K](f: (Char) ⇒ K): Map[K, String]
Hence, the result is in the form -
Map[Char,String]
The signature of groupBy
is given by-
def groupBy[K](f: (Char) ⇒ K): Map[K, List[Char]]
If it had been implicitly converted to List[Char] the result would be of the form -
Map[Char,List[Char]]
Now this should implicitly answer your curious question, as how scala figured out to groupBy
on Char
(see the signature) and yet give you Map[Char, String]
.