He-Pin commented on code in PR #990: URL: https://github.com/apache/incubator-pekko/pull/990#discussion_r1460409051
########## docs/src/test/scala/docs/stream/operators/sink/Exists.scala: ########## @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package docs.stream.operators.sink + +//#imports +import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.stream.scaladsl._ + +import scala.concurrent.ExecutionContext +//#imports + +object Exists { + + implicit val system: ActorSystem = null + implicit val ec: ExecutionContext = system.dispatcher + + def detectAnomaly(): Unit = { + // #exists + val source = Source(Seq("Sun is shining", "Unidentified Object", "River is flowing")) + + val anomalies = Seq("Unidentified Object") + def isAnomaly(phenomenon: String): Boolean = anomalies.contains(phenomenon) + + val result = source.runWith(Sink.exists(isAnomaly)) + result.map(println) Review Comment: May need await? The thread may.exsits so quickly ########## stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/FlowExistsSpec.scala: ########## @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.pekko.stream.scaladsl + +import org.apache.pekko.stream.testkit._ +import org.apache.pekko.stream.testkit.scaladsl._ +import org.scalatest.concurrent.ScalaFutures + +class FlowExistsSpec extends StreamSpec with ScalaFutures { + + "An Exists" must { + + def greaterThan3(i: Int) = i > 3 + + "emit true for empty Source" in { Review Comment: false? ########## stream-tests/src/test/java/org/apache/pekko/stream/javadsl/FlowTest.java: ########## @@ -306,6 +306,28 @@ public boolean test(Integer elem) { future.toCompletableFuture().get(3, TimeUnit.SECONDS); } + @Test + public void mustBeAbleToUseExists() throws Exception { + final TestKit probe = new TestKit(system); + final Source<Integer, NotUsed> source = Source.from(Arrays.asList(3, 4, 5)); + final Flow<Integer, Boolean, NotUsed> flow = + Flow.of(Integer.class) + .exists( + new Predicate<Integer>() { + public boolean test(Integer elem) { + return elem > 3; + } + }); + + final CompletionStage<Done> future = + source + .via(flow) + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); + + probe.expectMsgEquals(true); + future.toCompletableFuture().get(3, TimeUnit.SECONDS); Review Comment: Need an assertions -- 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]
