Hi,
What’s the idiomatic way of sharing headers between scenarios that have actions of different types?
If we define our actions in a list, map over it to add the common headers and then create a chain out of them we would naively write something like:
lazy val actions = List (
createTokenAction, getTokenAction, updateTokenAction(“REDEEMED”, 200),
findTokenAction, updateTokenAction(“EXPIRED”, 403), deleteTokenAction
)
val firstAction :: actionsWithHeaders = actions map (_ headers additionalHeaders)
override lazy val chain = actionsWithHeaders.foldLeft(exec(firstAction)) {
(c, a) => c.exec(a)
…which won’t compile. The type of actions is
List[AbstractHttpRequestBuilder[_ >: HttpRequestBuilder with HttpRequestWithParamsBuilder : AbstractHttpRequestBuilder[_ >: HttpRequestBuilder with HttpRequestWithParamsBuilder]]]
because we have both with and without params HttpBuilders and then the compiler cannot find any exec() with that type signature.
My guess is that there’s a much easier solution to factor out logic that you want applied to your actions. Simple pointers to idiomatic examples might suffice.
Thank you.
Vasco