Skip to content

Instantly share code, notes, and snippets.

@wheaties
Last active December 16, 2015 21:28
Show Gist options
  • Save wheaties/5499540 to your computer and use it in GitHub Desktop.
Save wheaties/5499540 to your computer and use it in GitHub Desktop.
Arbitrary Query object
trait Query[-A,+B,Cont[_] <: Iterable[_]] extends (A => Try[Cont[B]]){
self =>
def apply(arg0: A) = Try(unsafe(arg0))
protected def unsafe(arg0: A): Cont[B]
def map[C](f: B => C) = new Query[A,C,Cont]{
def unsafe(arg0: A) = self unsafe arg0 map f
}
def filter(p: B => Boolean) = new Query[A,B,Cont]{
def unsafe(arg0: A) = self unsafe arg0 filter f
}
def filterNot(p: B => Boolean) = filter(!p(_))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment