Skip to content

Instantly share code, notes, and snippets.

@Krasnyanskiy
Created April 16, 2016 16:09
Show Gist options
  • Save Krasnyanskiy/9c2f56ed5ee2e8b1423fea35ba89c34f to your computer and use it in GitHub Desktop.
Save Krasnyanskiy/9c2f56ed5ee2e8b1423fea35ba89c34f to your computer and use it in GitHub Desktop.
-scala: flatMap
abstract class List[+T] {
def flatMap[U](f: T => List[U]): List[U] = this match {
case x :: xs => f(x) ++ xs.flatMap(f) // ++ is a concat operator
case Nil => Nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment