Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stefanobaghino/36d46d5275647971d63fb8cd0e1fe836 to your computer and use it in GitHub Desktop.
Save stefanobaghino/36d46d5275647971d63fb8cd0e1fe836 to your computer and use it in GitHub Desktop.
Welcome to Scala 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.
scala> :paste
// Entering paste mode (ctrl-D to finish)
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
class RequestType {}
case object Read extends RequestType
case object Write extends RequestType
def dbrequest[T <: RequestType](d: T): Future[T] = {
d match {
case Read => println("reading"); Future(d)
case Write => println("writing"); Future(d)
}
}
// Exiting paste mode, now interpreting.
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
defined class RequestType
defined object Read
defined object Write
dbrequest: [T <: RequestType](d: T)scala.concurrent.Future[T]
scala> dbrequest(Read)
reading
res0: scala.concurrent.Future[Read.type] = Success(Read)
scala> dbrequest(Write)
writing
res1: scala.concurrent.Future[Write.type] = Success(Write)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment