He-Pin commented on code in PR #989:
URL: https://github.com/apache/incubator-pekko/pull/989#discussion_r1460746593
##########
stream/src/main/scala/org/apache/pekko/stream/scaladsl/Sink.scala:
##########
@@ -435,6 +436,24 @@ object Sink {
def foldAsync[U, T](zero: U)(f: (U, T) => Future[U]): Sink[T, Future[U]] =
Flow[T].foldAsync(zero)(f).toMat(Sink.head)(Keep.right).named("foldAsyncSink")
+ /**
+ * A `Sink` that will invoke the given function for every received element,
giving it its previous
+ * output (or the given `false`) and the element as input.
+ * * The returned [[scala.concurrent.Future]] will be completed with value
of the final
+ * function evaluation when the input stream ends, or completed with
`Failure`
+ * if there is a failure signaled in the stream.
+ */
+ def forall[T](predicate: T => Boolean): Sink[T, Future[Boolean]] = {
+ var acc = true
+ Flow[T].collectWhile {
+ case element if acc && predicate(element) => true
+ case _ if acc => acc = false; false
Review Comment:
As the graph can be materialize multi time , this can cause a problem. when
you run this graph several times.
Maybe you can try with `statefulMap`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]