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.
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.