scala - How call function which is return from another one? -
i trying call function marshal httpresponse spray. unmarshal function described here. response httpresponse
consider 3 code variants:
first
val func = unmarshal[mytype] func(response) second
unmarshal[mytype].apply(response) third
unmarshal[mytype](response) why third code variant not compile while first 2 works? compiler returns:
[error] found : spray.http.httpresponse [error] required: spray.httpx.unmarshalling.fromresponseunmarshaller[mytype] [error] (which expands to) spray.httpx.unmarshalling.deserializer[spray.http.httpresponse,mytype] [error] unmarshal[mytype](response) is there way call function returned unmarshal more elegant create temp variable or direct call apply method?
the signature of function (from link):
def unmarshal[t: fromresponseunmarshaller] so t needs implicit evidence there's such fromresponseunmarshaller it. signature compiles like:
def unmarshal[t](implicit evidence$1: fromresponseunmarshaller[t]): httpresponse ⇒ t that means, unmarshal function takes implicit parameter should transform mytype httpresponse.
in first example, call val func = unmarshal[mytype] makes compiler insert implicit you. in 3rd example,
unmarshal[mytype](response) response taking position of implicit parameter, supposed fromresponseunmarshaller, not httpresponse.
such call need be:
unmarshal[mytype](fromresponseunmarshsaller)(response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ original method call here apply response returned function.
Comments
Post a Comment