Skip to content

Instantly share code, notes, and snippets.

@LeifW
Created June 21, 2010 08:37
Show Gist options
  • Save LeifW/446588 to your computer and use it in GitHub Desktop.
Save LeifW/446588 to your computer and use it in GitHub Desktop.
import scala.xml.{Elem, NodeSeq}
object Match {
val input =
<square>
<double><val>3</val></double>
</square>
//def proc(input:NodeSeq):Function1[Int, Int] = input match {
def proc(input:NodeSeq):Int = input match {
case <square>{children @ _ *}</square> => {println("square"); 4* proc(children.filter(_.isInstanceOf[Elem])(0)) }
case <double>{children @ _ *}</double> => {println("double"); 2 * proc(children.filter(_.isInstanceOf[Elem])(0)) }
case x => x.text.toInt
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment