Last active
December 16, 2015 21:28
-
-
Save wheaties/5499540 to your computer and use it in GitHub Desktop.
Arbitrary Query object
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
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