scala - Play framework specs2 weird matcher syntax -


in play framework specs2 testing have these lines...

    new withapplication {       val homeresponse = route(fakerequest(get, "/")).get       val resulttype = contenttype(homeresponse)       resulttype.must( besome.which( _ == "text/html") )     } 

^ works, when pull " besome.which( _ == "text/html") " separate variable...

    new withapplication {       val homeresponse = route(fakerequest(get, "/")).get       val resulttype = contenttype(homeresponse)       val texttypematcher = besome.which( _ == "text/html")       resulttype.must( texttypematcher )     } 

^ type mismatch.

expected: matcher[option[string]], actual: optionlikecheckedmatcher[option, nothing, nothing] ^

what going on here?

in first case, infers type based on resulttype.must(, because resulttype string. when split it, there's nothing infer from, you'll get:

val texttypematcher = besome.which( _ == "text/html") => optionlikecheckedmatcher[option, nothing, nothing] 

but if add in type: besome[string], you'll correct type again.

val texttypematcher = besome[string].which( _ == "text/html") => optionlikecheckedmatcher[option, string, string] 

edit:

you can this:

val texttypematcher: optionlikecheckedmatcher[option, string, string] = besome.which( _ == "text/html") 

so basically, if give type inferrer work with, infer _ must string. otherwise, there no way scala know _ supposed string.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -