Accepted answer

You have to remove the y.tail from your recursive function and just use y (map the entire nested list - do not skip the first element).

def copyListReplace(tree: List[Any], p: Any => Any): List[Any] = { =>
    x match {
      case y: List[Any] => copyListReplace(y, p)
      case t => p(t)

Related Query

More Query from same tag