title: Play framework 2.3 ActionBuilder composition issue
body: <p>I really like play framework 2.3's ActionBuilder and the andThen method that allows you to dynamically compose actions.</p>
  
  <p>Here's a snippet of how I want to use action composition:</p>
  
  <pre><code>def showHomepage = RedirectingAction andThen
      AuthenticatedAction andThen NotificationAction async { request =&gt;
        Future {
          Ok(views.html.homepage.render(request.user, request.notifications ))
       }
   }
  </code></pre>
  
  <p>As you can guess, NotificationAction depends on AuthenticatedAction, and hence needs AuthenticatedRequest which contains the User object.</p>
  
  <p>The code complains on:</p>
  
  <pre><code>object NotificationAction extends ActionBuilder[NotificationAuthRequest] {
      def invokeBlock[A](request: AuthenticatedRequest[A], block: (NotificationAuthRequest[A]) =&gt; Future[Result]) = { ...
  </code></pre>
  
  <p>The error is: 
  object creation impossible, since method invokeBlock in trait ActionFunction of type [A](request: play.api.mvc.Request[A], block: controllers.v3.ScalaHomepageController.NotificationAuthRequest[A] => scala.concurrent.Future[play.api.mvc.Result])scala.concurrent.Future[play.api.mvc.Result] is not defined</p>
  
  <p>Apparently it allows only:  </p>
  
  <pre><code>def invokeBlock[A](request: Request[A], block: ...
  </code></pre>
  
  <p>but not:</p>
  
  <pre><code>def invokeBlock[A](request: AuthenticatedRequest[A], block: ...
  </code></pre>
  
  <p>I'd really appreciate if someone could throw light on this. Maybe my approach is wrong, but I don't like the idea of precomposed actions (like using ActionFunction) because I could have more actions that I could be mixing in at a later point.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>case class AuthenticatedRequest[A](val user: Option[User], request: Request[A]) extends  WrappedRequest(request)
  
  case class NotificationAuthRequest[A](val user: Option[User], val notifications: Option[List[UserNotificationData]], request: Request[A]) extends  WrappedRequest(request)
  
  
    object RedirectingAction extends ActionBuilder[Request] {
  
        def invokeBlock[A](request: Request[A], block: (Request[A]) =&gt; Future[Result]) = {
            Future {
              Redirect(REDIRECT_URL + request.uri + paramString)
            }
        }
    }
  
    object AuthenticatedAction extends ActionBuilder[AuthenticatedRequest] {
  
      def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) =&gt; Future[Result]) = {
        request.cookies.get("uid") map {
          cookie =&gt;
            val user = userClient.getUserById(userId(cookie)).get
            block(AuthenticatedRequest[A](user, request))
        } getOrElse {
          block(AuthenticatedRequest[A](userClient.getUserById(uid).get, request))
        }
      }
  
  
      def userId(cookie: Cookie) = {
        if(AppUtil.isProd) cookie.value else IMPERSONATE_ID.getOrElse(cookie.value)
      }
    }
  
    object NotificationAction extends ActionBuilder[NotificationAuthRequest] {
      def invokeBlock[A](request: AuthenticatedRequest[A], block: (NotificationAuthRequest[A]) =&gt; Future[Result]) = {
        request.user.map {
          user =&gt; block(NotificationAuthRequest[A](Some(user), userClient.getNotifications(user.getId).get.map(_.toList), request))
        }.getOrElse {
          block(NotificationAuthRequest[A](None, None, request))
        }
      }
    }
  </code></pre>