Tim,
your questions boils down to "How do I use the `directive.hmap`?".
This is how it works:
`hmap` is essentially the same as a regular `map`, only that it works on HLists rather than single values. We prefix methods working on HLists with a single `h` character so as to free up the name-space for the simple `map` and `flatMap` methods, that work on single-element HLists without requiring the little bit of HList boilerplate.
In your case you have a directive extracting two values (`optionalHeaderValueByName("foo") & optionalHeaderValueByName("bar")`) and you appear to want to map them.
This is how you do it:
underlyingDirective.hmap {
case foo :: bar :: HNil => expressionCreatingAnotherHList
}
All you need to do is to map an HList instance to another HList instance. In your case you apparently want to reduce the two values into a single one, so the whole thing would look like this:
underlyingDirective.hmap {
case foo :: bar :: HNil => foobarthing(foo, bar) :: HNil
}
> The foobarthing method returns a HttpRequest => MyThing, but i'm not sure
> how to thread the RequestContext into the directive definition…
What does foobarthing(…) logically do?
Does it extract a value from the request or create something you'd like to respond with?
In the first case you'll have to `hflatMap` rather than `hmap`:
underlyingDirective.hflatMap {
case foo :: bar :: HNil => extract(ctx => foobarthing(foo, bar)(ctx.request))
}
HTH and cheers,
Mathias
---
mat...@spray.io
http://spray.io
> --
> You received this message because you are subscribed to the Google Groups "spray-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
spray-user+...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>