Take a look at the full signature for flatten
:
def flatten[B](implicit asTraversable: (A) ⇒ GenTraversableOnce[B]): List[B]
As you can see, flatten
takes an implicit parameter. That parameter provides the rules for how to flatten the given collection types. If the compiler can’t find an implicit in scope then it can be provided explicitly.
flatten
can flatten almost anything as long as you provide the rules to do so.
solved flatten and flatMap in scala