-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new graph element: contextBypass
#15957
Comments
an alternative, maybe auxiliary option is to have a project-unproject element pair that works somewhat akin to lenses, maybe looking like this (draft):
where the final stream is a stream of case classes, |
Interesting. What would the API signature for |
I have no idea yet, I just dumped the idea here so we don't forget when discussing this ticket. |
@drewhk's use case if written in one function could look like this: projectedMap[T, U, A, B](project: T => A, unproject: (T, B) => U, f: ProcessorFlow[A, B]): ProcessorFlow[T, U] E.g. case class Person(name: String, age: Int)
val fixName: ProcessorFlow[String, String] = ...
projectedMap(_.name, (p, n) => p.copy(name = n), fixName): ProcessorFlow[Person, Person] In our case: val requestWithContext: (Ctx, HttpRequest) = ...
val userHandler: ProcessorFlow[HttpRequest, HttpResponse]
projectedMap(_._2, { case (ctx, response) => (ctx, response) }, userHandler): ProcessorFlow[(Ctx, HttpRequest), (Ctx, HttpResponse)] Another alternative would also be useful with this signature: projectedMapUnordered[T, U, A, B](project: T => A, unproject: (T, B) => U, f: A => Future[B]): ProcessorFlow[T, U] where |
The API is one thing, my proposal differs from the graph one that it lifts AST nodes automatically without needing a bcast-zip pair and therefore can handle one-to-many and many-to-one cases, too, like filter or mapSeq -- but this needs some internal support. |
Endre, I have no idea what you are talking about... :) |
Never mind, we will discuss it when the time comes, I am not sure I understand it either ;) |
Is this still valid? We currently have |
Yes, I think this ticket is still valid. |
As for me this can be very useful prebuilt combinator. Lot of cases maps directly to this flow.
|
Should be solved by WithContext, please re-open if not. |
@johanandren, I may not be completely understanding the original request here. Or perhaps I'm conflating it w/my own use case that I'm struggling with. But I don't think the WithContext implementation solves the problem. From the original ask, the "innerFlow" maps A to B. Correct me if I'm wrong, but in order for WithContext to work, A and B both would have to be capable of holding the context internally. But I don't think that's really a possibility in most cases. |
I think it works something like this:
Does that make sense? |
I think there is no |
What I was looking for when I came here and also when I first read about WithContext. I don't know whether this is the same as the original ask:
This above is close to the same use case as PassThroughFlow that I found in akka-contrib and alpakka, which, yes, I understand suffers from one-to-one limitation you mention above @jrudolph. My hope was that WithContext was actually solving that limitation. So I hear you saying that it does not. But does it serve the same purpose then as PassThrowFlow? I guess I'm not understanding the use case for WithContext. (The documentation is a bit thin.) |
This only helps if your inner flow explicitly support the context (but not as a tuple but as some custom wrapped type). I didn't even know about |
During the HTTP work we have discovered that we repeatedly build this stream graph setup:
This appears to be a setup that is of general utility and not in any way specific to HTTP. Here is how its API could look like:
The logic of the produced flow would be like this:
(Some(a), ctx)
the option is unpacked and its value sent through the inner flow. Thectx
is split off and sent through the bypass, where it is zipped with the corresponding element coming in from the inner flow to form a(Some(b), ctx)
tuple.(None, ctx)
thectx
is sent through the bypass without the inner flow seeing an element. The outer flow would then produce a(None, ctx)
element at the respective position in the element stream.Having
contextBypass
available would significantly simplify the HTTP stream definition on the server-side as well as on the client side.The text was updated successfully, but these errors were encountered: