I am trying to write a Value Class to add functionality to anything that implements Seq[_]
and allow it to make batch calls that return a Future[_]
(specifically, I am using it to make batch REST calls).
final class BatchedList[A, C[X] <: Seq[X]](val targetList: C[A]) extends AnyVal {
def batchRequests[B](batchSize: Int)(runner: Seq[A] => Seq[Future[Either[Result, B]]])
(implicit bf: CanBuildFrom[C[A], Either[Result, B], C[Either[Result, B]]]): Future[Either[Result, C[B]]] = {
targetList.grouped(batchSize).foldLeft(Future.successful(bf(targetList))) { (results, set) =>
results flatMap { responses =>
Future.sequence(runner(set)).map(responses ++=)
}
} map {
_.result().sequenceU
}
}
}
However, I can't get this to compile. I keep receiving the compiler error
value sequenceU is not a member of type parameter C[Either[play.api.mvc.Result,B]]
I've imported both scalaz._
and Scalaz._
, and I know they've provided a Traverse[_]
for my use case (which is List[_]
in this example). I'm pretty sure this is some sort of implicit resolution issue with the types, but I'm stumped on how to proceed forward resolving it.