質問

This is the code from https://github.com/eigengo/activator-spray-twitter/blob/master/src/main/scala/core/tweetstream.scala

What ~>(tilde arrow) operator does? I think that must be a operator of HttpRequest, but I could not find such operator in spray API.

I can figure out that authorize is a function which returns (HttpRequest => HttpRequest), so val rq must be a HttpRequest which returned value after applied by returned function of authorize.

def receive: Receive = {
    case query: String =>
      val body = HttpEntity(ContentType(MediaTypes.`application/x-www-form-urlencoded`), s"track=$query")
      val rq = HttpRequest(HttpMethods.POST, uri = uri, entity = body) ~> authorize
      sendTo(io).withResponsesReceivedBy(self)(rq)
    case ChunkedResponseStart(_) =>
    case MessageChunk(entity, _) => TweetUnmarshaller(entity).fold(_ => (), processor !)
    case _ =>
  }

Thanks in advance!

役に立ちましたか?

解決

The operator is just a function, and it is defined implicitly, see line 32 here.

Just think of it as compose. The operator takes the value to the left, and stuffs it as input into the function to the right.

A tip for how to find out things like these for yourself: Load the project into intellij idea or scala-IDE and just ctrl-click on the symbol. The IDE will take you to the definition.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top