feat: Add collectFirst stream operator. (#984)
This commit is contained in:
parent
cd70ae8a6a
commit
51b7ac519a
12 changed files with 275 additions and 1 deletions
|
|
@ -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 =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue