Posts

Showing posts with the label partialfunction

What is correct way to use operator orElse in Scala?

What is correct way to use operator orElse in Scala? I want to write two services, and then use orElse to make the two services combine together, which means service_one or service_two. They are all PartialFunctions. The service one is: val usersService = HttpService { case request @ GET -> Root / "users" / IntVar(userId) => Ok("test") } The service two is: val versionService = HttpService{ case req @ GET -> Root / "version" => { val jsonmap = ("origin" -> req.remoteAddr.getOrElse("unknown ip")) Ok(compact(render(jsonmap))) } } and then I want to combine then together. val service = userService orElse versionService //the error happens here. The error is: [error] F:workspacefrankcheckAPIsrcmainscalacomcardaccessServiceApp.scala:46: value orElse is not a member of org.http4s.HttpService [error] val service = usersService orElse versionService [error] ^ [error] one error foun...