Created
April 16, 2016 16:09
-
-
Save Krasnyanskiy/9c2f56ed5ee2e8b1423fea35ba89c34f to your computer and use it in GitHub Desktop.
-scala: flatMap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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