Source.range

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

Source operators

Dependency

The Akka dependencies are available from Akka’s library repository. To access them there, you need to configure the URL for this repository.

sbt
resolvers += "Akka library repository".at("https://repo.akka.io/maven")
Maven
<project>
  ...
  <repositories>
    <repository>
      <id>akka-repository</id>
      <name>Akka library repository</name>
      <url>https://repo.akka.io/maven</url>
    </repository>
  </repositories>
</project>
Gradle
repositories {
    mavenCentral()
    maven {
        url "https://repo.akka.io/maven"
    }
}
sbt
val AkkaVersion = "2.9.1"
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % AkkaVersion
Maven
<properties>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.typesafe.akka</groupId>
      <artifactId>akka-bom_${scala.binary.version}</artifactId>
      <version>2.9.1</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
<dependencies>
  <dependency>
    <groupId>com.typesafe.akka</groupId>
    <artifactId>akka-stream_${scala.binary.version}</artifactId>
  </dependency>
</dependencies>
Gradle
def versions = [
  ScalaBinary: "2.13"
]
dependencies {
  implementation platform("com.typesafe.akka:akka-bom_${versions.ScalaBinary}:2.9.1")

  implementation "com.typesafe.akka:akka-stream_${versions.ScalaBinary}"
}

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.

Examples

Define the range of integers.

Java
sourceimport akka.Done;
import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.actor.testkit.typed.javadsl.ManualTime;
import akka.actor.testkit.typed.javadsl.TestKitJunitResource;
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), system);

Reactive Streams semantics

emits when there is demand, the next value

completes when the end of the range has been reached

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.