* Add examples for zipWithIndex #25468 * better examples
This commit is contained in:
parent
0101740825
commit
68e382c7f9
3 changed files with 38 additions and 1 deletions
|
|
@ -4,8 +4,15 @@
|
|||
|
||||
package jdocs.stream.operators;
|
||||
|
||||
import akka.stream.Materializer;
|
||||
import akka.stream.javadsl.Flow;
|
||||
|
||||
//#zip-with-index
|
||||
import akka.stream.javadsl.Sink;
|
||||
import akka.stream.javadsl.Source;
|
||||
import java.util.Arrays;
|
||||
|
||||
//#zip-with-index
|
||||
//#log
|
||||
import akka.stream.Attributes;
|
||||
import akka.stream.javadsl.Source;
|
||||
|
|
@ -29,6 +36,16 @@ class SourceOrFlow {
|
|||
;
|
||||
}
|
||||
|
||||
void zipWithIndexExample() {
|
||||
Materializer materializer = null;
|
||||
//#zip-with-index
|
||||
Source.from(Arrays.asList("apple", "orange", "banana"))
|
||||
.zipWithIndex()
|
||||
.runWith(Sink.foreach(System.out::print), materializer);
|
||||
// this will print ('apple', 0), ('orange', 1), ('banana', 2)
|
||||
//#zip-with-index
|
||||
}
|
||||
|
||||
void conflateExample() {
|
||||
//#conflate
|
||||
Source.cycle(() -> Arrays.asList(1, 10, 100).iterator())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue