Created
June 21, 2010 08:37
-
-
Save LeifW/446588 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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