Lazy and fast concat and prepend (#30252)

This commit is contained in:
Johan Andrén 2021-05-27 17:18:47 +02:00 committed by GitHub
parent cbb12e6ef3
commit 4ade8ef2d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 825 additions and 77 deletions

View file

@ -19,7 +19,9 @@ import akka.japi.function.Function2;
// #zip-with-index
// #or-else
// #prepend
// #prependLazy
// #concat
// #concatLazy
// #interleave
// #merge
// #merge-sorted
@ -33,7 +35,9 @@ import java.util.*;
// #merge
// #interleave
// #concat
// #concatLazy
// #prepend
// #prependLazy
// #or-else
// #zip-with-index
// #zip-with
@ -124,6 +128,16 @@ class SourceOrFlow {
// #prepend
}
void prependLazyExample() {
// #prepend
Source<String, NotUsed> ladies = Source.from(Arrays.asList("Emma", "Emily"));
Source<String, NotUsed> gentlemen = Source.from(Arrays.asList("Liam", "William"));
gentlemen.prependLazy(ladies).runWith(Sink.foreach(System.out::print), system);
// this will print "Emma", "Emily", "Liam", "William"
// #prepend
}
void concatExample() {
// #concat
Source<Integer, NotUsed> sourceA = Source.from(Arrays.asList(1, 2, 3, 4));
@ -134,6 +148,16 @@ class SourceOrFlow {
// #concat
}
void concatLazyExample() {
// #concat
Source<Integer, NotUsed> sourceA = Source.from(Arrays.asList(1, 2, 3, 4));
Source<Integer, NotUsed> sourceB = Source.from(Arrays.asList(10, 20, 30, 40));
sourceA.concatLazy(sourceB).runWith(Sink.foreach(System.out::print), system);
// prints 1, 2, 3, 4, 10, 20, 30, 40
// #concat
}
void interleaveExample() {
// #interleave
Source<Integer, NotUsed> sourceA = Source.from(Arrays.asList(1, 2, 3, 4));