Rich Hickey said
“What's the common thing that all bugs in the wild share? They passed the type-checker, they passed all the tests!”
private def flattenAnything(x: Any): Seq[Object] = x match {
case so: Seq[Object] => so flatMap (flattenAnything)
case ob: Object => List(ob)
case junk: Any => throw new IllegalArgumentException("Cannot flatten " + junk)
}