I have a Service that looks like this:
The Tagless final trait:
trait ProvisioningAPIService[M[_]] {
def provisionAPI(request: Request): M[Response]
}
And somewhere in my implementation, I have the following:
class ProvisioningService extends ProvisioningAPIService[Task] {
def provisionAPI(request: Request): Task[Response] = Task {
Response("response from server")
}
}
This is fine, but I would like to still delay that and pass in the effect only when I instantiate a new version of my ProvisioningService. For example., I would like to have something like this:
class ProvisioningService[M[_]: Monad](implicit monad: Monad[M[_]) extends ProvisioningAPIService[M] {
def provisionAPI(request: Request): M[Response] = /* some wrapper that would be resolved at runtime */ {
Response("response from server")
}
}
And during runtime, I do the following:
val privisioingServiceAsTask = new ProvisioningService[Task]
So basically I do not provide a concrete implemenattion during compile time, but I create an instance of my ProvisioningService passing in an effect at Runtime. How can I do this?