ssledz blog

Everything should be made as simple as possible, but no simpler.

Playing With Scala - Writing Function : Flatten

Few weeks ago since now :) I started participating in a course ‘Functional Programming Principles in Scala’ by Martin Odersky. I have already completed 4 weeks (course consists of 6 weeks) and I can tell honestly that this is the best course I’ve ever been doing.

My knowledge about scala is still increasing !

Below you can find a sample of what I can now do. The problem is to implement function flatten(xs: List[Any]): List[Any] which takes a list of anything an tries to flatten it. For example

1
flatten(List(List(1, 1), 2, List(3, List(5, 8))))

should return a following list

1
List[Any] = List(1, 1, 2, 3, 5, 8)

At the end I would like to say ‘thank you’ to Atlassian company for paying a half for this course !

Comments