Friday, 1 May 2009

Scala - Flatten lists & use asInstanceOf

 
def flatten3(l: List[_]): List[_] = {
l.flatMap(a => {
if (a.isInstanceOf[List[_]]) flatten3(a.asInstanceOf[List[_]])
else List(a)
})
}

No comments:

Post a comment