Created
July 17, 2011 10:54
-
-
Save eed3si9n/1087455 to your computer and use it in GitHub Desktop.
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
| trait CanWhere[A] { | |
| def apply(f: PartialFunction[A, A]): Selector[Node] | |
| } | |
| implicit val stringToCanWhere = new CanWhere[String] { | |
| def apply(f: PartialFunction[String, String]) = | |
| Selector({ case Elem(p, name, a, s, c) if f.isDefinedAt(name) => Elem(p, f(name), a, s, c) }) | |
| } | |
| implicit val nodeToCanWhere = new CanWhere[Node] { | |
| def apply(f: PartialFunction[Node, Node]) = | |
| Selector({ case e: Elem if f.isDefinedAt(e) => f(e) }) | |
| } | |
| /** | |
| * Converts [[PartialFunction]]`[A, A]` into an instance of [[com.codecommit.antixml.Selector]] | |
| * which can then be passed to the appropriate methods on [[com.codecommit.antixml.Group]]. | |
| * For example: `ns \ where { case "name" => "alternative" }` | |
| */ | |
| def where[A: CanWhere](f: PartialFunction[A, A]): Selector[Node] = implicitly[CanWhere[A]].apply(f) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment