Created
June 13, 2011 20:39
-
-
Save retronym/1023634 to your computer and use it in GitHub Desktop.
attribute-extractor.scala
This file contains hidden or 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
scala> import xml._ | |
import xml._ | |
scala> class Attr(name: String) { def unapply(e: Elem) = e.attribute(name).map(_.text) } | |
defined class Attr | |
scala> val IdAttr = new Attr("id") | |
IdAttr: Attr = Attr@6b2dc21d | |
scala> <a id="123"/> match { case IdAttr("123") => "!" }res3: java.lang.String = ! | |
scala> <a id="123"/> match { case IdAttr(id) => id } | |
res4: String = 123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment