Problem
I have two classes that look like this:
class Now {
def do[A](f: Int => A): Seq[A]
}
class Later {
def do[A](f: Int => A): Future[Seq[A]]
}
The only difference between the two classes is that Now returns Seq, and later returns Future Seq. I would like these two classes to have the same interface
What i tried
This seemed to be ideal for higher types, given how Seq and Future [Seq] should have only one type parameter.
trait Do[F[_]] {
def do[A](f: Int => A): F[A]
}
// Compiles
class Now extends Do[Seq] {
def do[A](f: Int => A): Seq[A]
}
// Does not compile. "type Seq takes type parameters" and
// "scala.concurrent.Future[<error>] takes no type parameters, expected: one"
class Later extends Do[Future[Seq]] {
def do[A](f: Int => A): Future[Seq[A]]
}
Am I using higher type types incorrectly? Am I delivering the future [Seq] wrong? Is there a way to allow Now and Later to use the same interface?
source
share