following the play websockets example i run into a weird problem.
the following example from the docs is working:
Future.successful(request.session.get("user") match {
case None => Left(Forbidden)
case Some(_) => Right(out => ChannelActor.props(out, "", ""))
})
to understand the code I tried to play around with the code:
Future.successful({
val test = request.session.get("user") match {
case None => Left(Forbidden)
case Some(_) => Right(out => ChannelActor.props(out, "", ""))
}
test
})
the compiler complains, that there is a "missing parameter type" for the value out
.
Why is that? I just added the saved the Either in test and returned this val instead of the match statement itself.
thanks
The reason is that the Scala compiler cannot infer the type of
out
. You never tell the compiler (or reader) what typeout
actually is. You can see that it is a functions returns typeProps
, but what type if its input is is never specified. Therefore, the type information you can derive from this code is justFuture[Either[Result, ??? => Props]
.You solved this by annotating this handler function
val handler: HandlerProps
which is an alias forval handler: ActorRef => Props
. So by annotating it with type information, you supplied the Scala compiler with enough type information to compile this. You can also do this by writingRight(out: ActorRef => ChannelActor.props(out, "", ""))
, or writingval test: Either[Result, HandlerProps] = ... match {
.