n8han/Databinder-Dispatch — Issue #55: Option mappable request building method
Author: softprops
Created: 2011-10-28 01:42:50+00:00
State: open

This is just an idea pitch.

What do you think of adding some kind of `map`'ing method on dispatch.Request that will build up a request given an Option of String as an expression

I did something like this in `ls` where I defined a implicit method on request [1] of something like

implicit def pathMappableRequest(r: dispatch.Request) = new {
def /?(p: Option[String]) = p.map(r / _).getOrElse(r)
}

Where the usage was something like a method [2] that took optional input and conditionally build up a request

def lib(name: String, version: Option[String] = None)(
user: Option[String])(repo: Option[String]) =
api / "libraries" / name /? version /? user /? repo

I'm not sold on the method name (it looks too much like I'm about to build up a query string) but I think something like this would be useful. Something where you can build up a request as an expression with optional parts.

Wdyt?

[1]: https://github.com/softprops/ls/blob/master/plugin/src/main/scala/client.scala#L9-11
[2]: https://github.com/softprops/ls/blob/master/plugin/src/main/scala/client.scala#L22-24