Lazy and fast concat and prepend (#30252)
This commit is contained in:
parent
cbb12e6ef3
commit
4ade8ef2d1
17 changed files with 825 additions and 77 deletions
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue