Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Flatten {
- def flatten[A](xss : List[List[A]]) : List[A] =
- xss match {
- case Nil => List[A]() //Base case <=> end of list
- case head :: tail => { //Can be separated into head and tail
- var xs = flatten(tail) //Find end of tail
- for (i <- (head.length-1 to 0 by -1)) { //Add head to tail
- xs = head(i) :: xs
- }
- xs //return new list
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement