Alexey's solution is very clever and answers the question you made. However, I think you made the from question.
You started with these two interfaces:
class Now {
def do[A](f: Int => A): Seq[A]
}
class Later {
def do[A](f: Int => A): Future[Seq[A]]
}
and want to modify Later
so it implements this:
trait Do[F[_]] {
def do[A](f: Int => A): F[A]
}
However, you are losing an opportunity here to abstract away whether something is now or later. You should instead change Do
to be like this:
trait Do[F[_]] {
def do[A](f: Int => A): F[Seq[A]]
}
And change Now
to this:
class Now {
def do[A](f: Int => A): Need[Seq[A]]
}
Here, Need is a Scalaz monad that basically acts like a lazy identity to the object it contains. There are other alternatives in the same vein, but the point is that the only thing you need to know about Future
and Need
is that they are monads. You treat them the same, and you make the decision to use one or the other elsewhere.