Does away with this pesky compiler warning in scala 2.10.0 "`withFilter' method does not yet exist on org.json4s.JValue, using `filter' method instead"
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 org.json4s.JValue | |
implicit class LiftJValueWithFilter(self: JValue) | |
extends JValueWithFilter(self, _ => true) | |
class JValueWithFilter(self: JValue, p: JValue => Boolean) { | |
def map(f: JValue => T): List[T] = | |
self.filter(p).map(f) | |
def flatMap(f: JValue => List[T]): List[T] = | |
self.filter(p).flatMap(f) | |
def foreach(f: JValue => Unit): Unit = | |
self.filter(p).foreach(f) | |
def withFilter(q: JValue => Boolean): JValueWithFilter = | |
new JValueWithFilter(self, x => p(x) && q(x)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot! Obvious, but so useful!