-
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
SourceWithContext and FlowWithContext #25951
Conversation
Thank you for your pull request! After a quick sanity check one of the team will reply with 'OK TO TEST' to kick off our automated validation on Jenkins. This compiles the project, runs the tests, and checks for things like binary compatibility and source code formatting. When two team members have also manually reviewed and (perhaps after asking for some amendments) accepted your contribution, it should be good to be merged. For more details about our contributing process, check out CONTRIBUTING.md - and feel free to ask! |
OK TO TEST |
Test PASSed. |
Test PASSed. |
1 similar comment
Test PASSed. |
Test PASSed. |
Test FAILed. |
Test FAILed. |
I cleaned up things and added scaladoc everywhere. From my side this is ready to go with this first set of supported operations. |
* accessing the delegate | ||
*/ | ||
@InternalApi | ||
private[stream] abstract class GraphDelegate[+S <: Shape, +Mat](delegate: Graph[S, Mat]) extends Graph[S, Mat] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
@jrudolph nice simplifications and cleanups! |
Test PASSed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I have asked @RayRoestenburg to squash into 2 commits (Ray/Johannes) and then we can merge this.
…ceWithContext and FlowWithContext
215be72
to
a2c811d
Compare
Test PASSed. |
Great work @RayRoestenburg and @jrudolph |
/** | ||
* Apply the given function to each context element (leaving the data elements unchanged). | ||
*/ | ||
def mapContext[Ctx2](f: Ctx ⇒ Ctx2): Repr[Ctx2, Out] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice too
Sorry for the late review, I only just learnt about this. I suspect a common pattern might be where users don't care about what the context is, they just want a flow that carries whatever context the container (eg, pipelines, or Akka projections) wants to provide. Then, the same flow can be used in multiple situations with different contexts, eg carrying a Kafka context in production, or carrying some dummy context in tests. An example would be in the Akka projections library, when you define a projection, the context is irrelevant. With this API, I could imagine Akka projections might provide something that looks like this: trait Projection[In, Out] {
def projection[Ctx]: FlowWithContext[In, Ctx, Out, Ctx, _]
} And then the user would implement it like this: class MyProjection extends Projection[MyIn, MyOut] {
override def projection[Ctx] = FlowWithContext[MyIn, Ctx].map(myInToMyOut)
} The question for me then is, can we possibly drop the context type variable somehow? It's not so bad for Scala, but for Java the signatures have the potential to be quite overbearing. I realise that the reason the context type variable is needed is to provide trait ViaWithContext[In, Out, Mat] {
def apply[Ctx]: Flow[(In, Ctx), (Out, Ctx), Mat]
}
def via[Out, Mat](flow: ViaWithContext[In, Out, Mat]): FlowWithContext[In, Out, Mat] And maybe that could be implemented with a lambda because it's a SAM? The same might work in Java? I'm not sure, the |
I agree that a FlowWithContext without a fixed context would be a good thing. I had a try at getting that to work but it was non-trivial to get right so we settled for the straight-forward API for now (even if that means extra type parameters). In any case, we'd like to keep the API surface minimal. If we want a generic If we can achieve that, I'm all for doing it, it's not to late to iterate on the API (and @raboof also had ideas for improvements he wants to try out at some point). |
Based on earlier work by Johannes
I have added
ApiMayChange
@patriknw @jrudolph and processed @2m comments. Let me know if anything more is required for now.