He-Pin commented on code in PR #989:
URL: https://github.com/apache/incubator-pekko/pull/989#discussion_r1460861990
##########
stream/src/main/scala/org/apache/pekko/stream/scaladsl/Sink.scala:
##########
@@ -445,12 +445,9 @@ object Sink {
* 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
- }.statefulMap(() => true)((state, bool) => (state && bool, bool), bool =>
Some(bool))
- .toMat(Sink.last)(Keep.right).named("forallSink")
+ Flow[T].statefulMap(() => true)((state, ele) => (predicate(ele), state),
bool => Some(bool))
+ .takeWhile(s => s, inclusive = true)
+ .toMat(Sink.last)(Keep.right)
Review Comment:
Cool, I have a pending PR, which will help this.
--
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]