Skip to content

Instantly share code, notes, and snippets.

@wheaties
Forked from frankleonrose/IsNotFuture
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wheaties/a49e2f5c2e1e3c3286f3 to your computer and use it in GitHub Desktop.
Save wheaties/a49e2f5c2e1e3c3286f3 to your computer and use it in GitHub Desktop.
trait IsNotFuture[+F]
object IsNotFuture{
def apply[F](implicit isf: IsNotFuture[F]) = isf
implicit def mkFuture[A] = new IsNotFuture[Future[A]] {}
implicit object isf extends IsNotFuture[Any] {}
}
//No need for a dependent type. All you need is the implicit ambiguity.
def inSession[T](fn: (Session) => T)(implicit isNotFuture: IsNotFuture[T]): T = {
db withSession fn
}
// Compiler fails as desired
inSession { session => Future(1) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment