feat: Add collectFirst stream operator. (#984)

This commit is contained in:
He-Pin(kerr) 2024-01-20 19:39:22 +08:00 committed by GitHub
parent cd70ae8a6a
commit 51b7ac519a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 275 additions and 1 deletions

View file

@ -66,6 +66,7 @@ import org.apache.pekko.stream.Attributes;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
import java.util.stream.Collectors;
class SourceOrFlow {
@ -412,6 +413,19 @@ class SourceOrFlow {
// #collectWhile
}
void collectFirstExample() {
// #collectFirst
Source.from(Arrays.asList(1, 3, 5, 7, 8, 9, 10))
.collectFirst(
PFBuilder.<Integer, Integer>create()
.match(Integer.class, i -> i % 2 == 0, i -> i)
.build())
.runWith(Sink.foreach(System.out::println), system);
// expect prints output:
// 8
// #collectFirst
}
void collectTypeExample() {
// #collectType
Flow<Message, Pong, NotUsed> flow =