Here is the correction, as per the comments:
def traverse[T](rowVisitor: (Row, Content => T) => T)(containerVisitor: Container => T): T = {
def descend(node: Content): T = node match {
case Row(columns) => rowVisitor(Row(columns), descend)
case Container(name) => containerVisitor(Container(name))
}
descend(contentTree)
}
I also split the parameter list so that it can be called like:
layout.traverse[OutputType] { (row, descend) =>
/* call descend on each column of the row, and then aggregate to OutputType */
} { container =>
/* do something with container producing OutputType */
}
It seems to require an explicit type parameter specification or an explicit type on descend
in the first anonymous function to compile. Not sure there's a way around that.