Created
July 5, 2017 07:37
-
-
Save stefanobaghino/36d46d5275647971d63fb8cd0e1fe836 to your computer and use it in GitHub Desktop.
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
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