mdedetrich commented on code in PR #1422: URL: https://github.com/apache/pekko/pull/1422#discussion_r1703180929
########## stream/src/main/scala/org/apache/pekko/stream/scaladsl/Flow.scala: ########## @@ -428,6 +428,57 @@ object Flow { */ def fromFunction[A, B](f: A => B): Flow[A, B, NotUsed] = apply[A].map(f) + /** + * Creates a FlowW from an existing base Flow outputting an optional element and + * applying an additional viaFlow only if the element in the stream is defined. + * + * '''Emits when''' the provided viaFlow is runs with defined elements + * + * '''Backpressures when''' the viaFlow runs for the defined elements and downstream backpressures + * + * '''Completes when''' upstream completes + * + * '''Cancels when''' downstream cancels + * + * @param flow The base flow that outputs an optional element + * @param viaFlow The flow that gets used if the optional element in is defined. + * @param combine How to combine the materialized values of flow and viaFlow + * @return a Flow with the viaFlow applied onto defined elements of the flow. The output value + * is contained within an Option which indicates whether the original flow's element had viaFlow + * applied. + * @since 1.1.0 + */ + def optionalVia[FIn, FOut, FViaOut, FMat, FViaMat, Mat](flow: Flow[FIn, Option[FOut], FMat], Review Comment: The optional is necessary for the problem I am solving since 1. I need to keep the elements that don't fulfill the predicate (i.e. I am using `StreamWithContext`/`FlowWithContext` and I don't want to lose the context) 2. I want to know which elements were filtered and which weren't after the matter of fact, so even if this was changed to a predicate it wouldn't ultimately save on performance as I would manually have to add the functionality to achieve this. I am not against adding an alternative version that avoids boxing due to using a predicate but I would suggest to do that in a different PR, and as @raboof pointed out earlier that may not even need a specific utility function depending on whether point 2 is important or not. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org For additional commands, e-mail: notifications-h...@pekko.apache.org