Scala version: 2.11.8
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import play.api.mvc._
object foooo {
type ActionFilter[R] = R => Future[Either[Int, Unit]]
case class FooRequest[A](request: Request[A]) extends WrappedRequest(request)
implicit class ActionFilterOps[R](val f: ActionFilter[R]) {
def * (f1: ActionFilter[R]): ActionFilter[R] = { (r: R) =>
f(r).flatMap {
case Left(r) => Future.successful(Left(r))
case Right(_) => f1(r)
}
}
}
def test[A]() = {
val f0: ActionFilter[FooRequest[A]] = { (r: FooRequest[A]) =>
Future.successful(Left(1))
}
val f1 = f0
ActionFilterOps(f1) * f0 // Ok
f1 * f0 // Won't compile
}
}
As you can see, implicit class not work. I have to new the ActionFilterOps
As a side note: it helps if you have a self contained example that does not depend on external dependencies (such as Play) if that is possible.
Now onto the answer, or at least fix of the error... If you change the type alias
ActionFilter
to a class that wraps a function it works.It also works if you use the raw function type instead of the type alias.
Especially that second "solution" makes me think that this is a bug.