Skip to content

Instantly share code, notes, and snippets.

@softprops
Last active December 17, 2015 03:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softprops/5542495 to your computer and use it in GitHub Desktop.
Save softprops/5542495 to your computer and use it in GitHub Desktop.
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"
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))
}
@vpatryshev
Copy link

Thanks a lot! Obvious, but so useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment