score:5

Accepted answer

combine the seqs first. it's cheaper to use an iterator, which won't create an intermediate collection.

scala> val as = seq(1,2,3) ; val bs = seq.empty[int]
as: seq[int] = list(1, 2, 3)
bs: seq[int] = list()

scala> (as ++ bs).mkstring("|")
res0: string = 1|2|3

scala> (as.iterator ++ bs).mkstring("|")
res1: string = 1|2|3

that is,

case block(fields, children) => (fields.iterator ++ children).map(_.format).mkstring("|")

score:3

trait cda {
  def format: string = this match {
    case f: field => f.value
    case block(fields, children) => fields.map(f => f.format).mkstring("|") + {if (!children.isempty) {"|" + children.map(b => b.format).mkstring("|")} else ""}
    case record(keys, blocks) => blocks.map(b => b.format).mkstring("|")
  }
}

Related Query

More Query from same tag