Implementing List#flatMap

Viewed 4785

Is there a better functional way to write flatMap?

def flatMap[A,B](list: List[A])(f: A => List[B]): List[B] =
    list.map(x => f(x)).flatten

Conceptually, I understand flatMap in terms of flatten.

3 Answers
Related