http4s/http4s — pull request #53 by rossabaker (2014-09-05 15:52:30+00:00)
Title: Change HttpService to Request => OptionT[Task, Response]

Pros:
* Middlewares are now simpler to write correctly. Instead of implementing `isDefinedAt`, `applyOrElse`, and `apply` lawfully, it's just `apply`.
* Totality rules, partiality drools. There's no way back to a Task[Response] without providing a default.
* Opens the door to services asynchronously deciding whether they can handle a request. This is not seen in the wild today, but would be highly useful for implementing `pass` in DSL like Scalatra or Unfiltered.

Cons:
* PartialFunction is more widely understood than OptionT. I don't expect that to be a problem for most of our audience, but I started down this functional road some time before I'd grokked monad transformers.
* Introduces `HttpService { ... }` syntax to continue to use PartialFunction literals. These will most frequently be seen in http4s-dsl.
* Middlewares that emphasize the Task monad, rather than Option or no monad, get a little more verbose. See timeout and the collectResponse portion of PushSupport.
* Slight overhead of monad transformer. Has not been measured, and I don't expect it to be significant, but this will be a little heavier.

Improvements found here that could as easily be bolted onto the existing code:
* HttpService.map
* HttpService.or
* HttpService.orNotFound
* Changing `route` to `service`