Source.range

Emit each integer in a range, with an option to take bigger steps than 1.

Source operators

Dependency

sbt
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.5.32"
Maven
<dependencies>
  <dependency>
    <groupId>com.typesafe.akka</groupId>
    <artifactId>akka-stream_2.12</artifactId>
    <version>2.5.32</version>
  </dependency>
</dependencies>
Gradle
dependencies {
  implementation "com.typesafe.akka:akka-stream_2.12:2.5.32"
}

Description

Emit each integer in a range, with an option to take bigger steps than 1. In Scala, use the apply method to generate a sequence of integers.

emits when there is demand, the next value

completes when the end of the range has been reached

Examples

Define the range of integers.

Java
sourceimport akka.NotUsed;
import akka.actor.ActorSystem;
import akka.actor.testkit.typed.javadsl.ManualTime;
import akka.actor.testkit.typed.javadsl.TestKitJunitResource;
import akka.stream.ActorMaterializer;
import akka.stream.Materializer;
import akka.stream.javadsl.Source;

Source<Integer, NotUsed> source = Source.range(1, 100);

Source<Integer, NotUsed> sourceStepFive = Source.range(1, 100, 5);

Source<Integer, NotUsed> sourceStepNegative = Source.range(100, 1, -1);

Print out the stream of integers.

Java
sourcesource.runForeach(i -> System.out.println(i), materializer);
Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.