diff --git a/akka-docs/src/test/java/jdocs/stream/operators/SourceOrFlow.java b/akka-docs/src/test/java/jdocs/stream/operators/SourceOrFlow.java index e990860166..35473947d9 100644 --- a/akka-docs/src/test/java/jdocs/stream/operators/SourceOrFlow.java +++ b/akka-docs/src/test/java/jdocs/stream/operators/SourceOrFlow.java @@ -86,7 +86,7 @@ class SourceOrFlow { // #zip-with-index Source.from(Arrays.asList("apple", "orange", "banana")) .zipWithIndex() - .runWith(Sink.foreach(System.out::print), system); + .runForeach(System.out::println, system); // this will print ('apple', 0), ('orange', 1), ('banana', 2) // #zip-with-index } @@ -95,7 +95,7 @@ class SourceOrFlow { // #zip Source sourceFruits = Source.from(Arrays.asList("apple", "orange", "banana")); Source sourceFirstLetters = Source.from(Arrays.asList("A", "O", "B")); - sourceFruits.zip(sourceFirstLetters).runWith(Sink.foreach(System.out::print), system); + sourceFruits.zip(sourceFirstLetters).runForeach(System.out::println, system); // this will print ('apple', 'A'), ('orange', 'O'), ('banana', 'B') // #zip @@ -109,7 +109,7 @@ class SourceOrFlow { .zipWith( sourceFruits, (Function2) (countStr, fruitName) -> countStr + " " + fruitName) - .runWith(Sink.foreach(System.out::print), system); + .runForeach(System.out::println, system); // this will print 'one apple', 'two orange', 'three banana' // #zip-with @@ -119,7 +119,7 @@ class SourceOrFlow { // #prepend Source ladies = Source.from(Arrays.asList("Emma", "Emily")); Source gentlemen = Source.from(Arrays.asList("Liam", "William")); - gentlemen.prepend(ladies).runWith(Sink.foreach(System.out::print), system); + gentlemen.prepend(ladies).runForeach(System.out::println, system); // this will print "Emma", "Emily", "Liam", "William" // #prepend @@ -129,7 +129,7 @@ class SourceOrFlow { // #prepend Source ladies = Source.from(Arrays.asList("Emma", "Emily")); Source gentlemen = Source.from(Arrays.asList("Liam", "William")); - gentlemen.prependLazy(ladies).runWith(Sink.foreach(System.out::print), system); + gentlemen.prependLazy(ladies).runForeach(System.out::println, system); // this will print "Emma", "Emily", "Liam", "William" // #prepend @@ -139,7 +139,7 @@ class SourceOrFlow { // #concat Source sourceA = Source.from(Arrays.asList(1, 2, 3, 4)); Source sourceB = Source.from(Arrays.asList(10, 20, 30, 40)); - sourceA.concat(sourceB).runWith(Sink.foreach(System.out::print), system); + sourceA.concat(sourceB).runForeach(System.out::println, system); // prints 1, 2, 3, 4, 10, 20, 30, 40 // #concat @@ -149,7 +149,7 @@ class SourceOrFlow { // #concat Source sourceA = Source.from(Arrays.asList(1, 2, 3, 4)); Source sourceB = Source.from(Arrays.asList(10, 20, 30, 40)); - sourceA.concatLazy(sourceB).runWith(Sink.foreach(System.out::print), system); + sourceA.concatLazy(sourceB).runForeach(System.out::println, system); // prints 1, 2, 3, 4, 10, 20, 30, 40 // #concat @@ -159,7 +159,7 @@ class SourceOrFlow { // #interleave Source sourceA = Source.from(Arrays.asList(1, 2, 3, 4)); Source sourceB = Source.from(Arrays.asList(10, 20, 30, 40)); - sourceA.interleave(sourceB, 2).runWith(Sink.foreach(System.out::print), system); + sourceA.interleave(sourceB, 2).runForeach(System.out::println, system); // prints 1, 2, 10, 20, 3, 4, 30, 40 // #interleave @@ -169,7 +169,7 @@ class SourceOrFlow { // #merge Source sourceA = Source.from(Arrays.asList(1, 2, 3, 4)); Source sourceB = Source.from(Arrays.asList(10, 20, 30, 40)); - sourceA.merge(sourceB).runWith(Sink.foreach(System.out::print), system); + sourceA.merge(sourceB).runForeach(System.out::println, system); // merging is not deterministic, can for example print 1, 2, 3, 4, 10, 20, 30, 40 // #merge @@ -180,11 +180,11 @@ class SourceOrFlow { Source sourceA = Source.from(Arrays.asList(1, 2, 3, 4)); Source sourceB = Source.from(Arrays.asList(10, 20, 30, 40)); - sourceA.mergePreferred(sourceB, false, false).runWith(Sink.foreach(System.out::print), system); + sourceA.mergePreferred(sourceB, false, false).runForeach(System.out::println, system); // prints 1, 10, ... since both sources have their first element ready and the left source is // preferred - sourceA.mergePreferred(sourceB, true, false).runWith(Sink.foreach(System.out::print), system); + sourceA.mergePreferred(sourceB, true, false).runForeach(System.out::println, system); // prints 10, 1, ... since both sources have their first element ready and the right source is // preferred // #mergePreferred @@ -195,9 +195,7 @@ class SourceOrFlow { Source sourceA = Source.from(Arrays.asList(1, 2, 3, 4)); Source sourceB = Source.from(Arrays.asList(10, 20, 30, 40)); - sourceA - .mergePrioritized(sourceB, 99, 1, false) - .runWith(Sink.foreach(System.out::print), system); + sourceA.mergePrioritized(sourceB, 99, 1, false).runForeach(System.out::println, system); // prints e.g. 1, 10, 2, 3, 4, 20, 30, 40 since both sources have their first element ready and // the left source has higher priority – if both sources have elements ready, sourceA has a // 99% chance of being picked next while sourceB has a 1% chance @@ -210,13 +208,13 @@ class SourceOrFlow { Source sourceB = Source.from(Arrays.asList(2, 4, 6, 8)); sourceA .mergeSorted(sourceB, Comparator.naturalOrder()) - .runWith(Sink.foreach(System.out::print), system); + .runForeach(System.out::println, system); // prints 1, 2, 3, 4, 5, 6, 7, 8 Source sourceC = Source.from(Arrays.asList(20, 1, 1, 1)); sourceA .mergeSorted(sourceC, Comparator.naturalOrder()) - .runWith(Sink.foreach(System.out::print), system); + .runForeach(System.out::println, system); // prints 1, 3, 5, 7, 20, 1, 1, 1 // #merge-sorted } @@ -227,10 +225,10 @@ class SourceOrFlow { Source source2 = Source.from(Arrays.asList("Second source")); Source emptySource = Source.empty(); - source1.orElse(source2).runWith(Sink.foreach(System.out::print), system); + source1.orElse(source2).runForeach(System.out::println, system); // this will print "First source" - emptySource.orElse(source2).runWith(Sink.foreach(System.out::print), system); + emptySource.orElse(source2).runForeach(System.out::println, system); // this will print "Second source" // #or-else @@ -471,7 +469,7 @@ class SourceOrFlow { Source longWords = words.filter(w -> w.length() > 6); - longWords.runWith(Sink.foreach(System.out::print), system); + longWords.runForeach(System.out::println, system); // consectetur // adipiscing // eiusmod @@ -490,7 +488,7 @@ class SourceOrFlow { Source longWords = words.filterNot(w -> w.length() <= 6); - longWords.runWith(Sink.foreach(System.out::print), system); + longWords.runForeach(System.out::println, system); // consectetur // adipiscing // eiusmod @@ -503,7 +501,7 @@ class SourceOrFlow { Source fiveIntegers = Source.from(Arrays.asList(1, 2, 3, 4, 5)); Source droppedThreeInts = fiveIntegers.drop(3); - droppedThreeInts.runWith(Sink.foreach(System.out::print), system); + droppedThreeInts.runForeach(System.out::println, system); // 4 // 5 // #drop @@ -514,7 +512,7 @@ class SourceOrFlow { Source droppedWhileNegative = Source.from(Arrays.asList(-3, -2, -1, 0, 1, 2, 3, -1)).dropWhile(integer -> integer < 0); - droppedWhileNegative.runWith(Sink.foreach(System.out::print), system); + droppedWhileNegative.runForeach(System.out::println, system); // 1 // 2 // 3