Source.range

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

Source operators

Dependency

sbt
val PekkoVersion = "1.1.2+24-bcd44ee3-SNAPSHOT"
libraryDependencies += "org.apache.pekko" %% "pekko-stream" % PekkoVersion
Maven
<properties>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.pekko</groupId>
      <artifactId>pekko-bom_${scala.binary.version}</artifactId>
      <version>1.1.2+24-bcd44ee3-SNAPSHOT</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
<dependencies>
  <dependency>
    <groupId>org.apache.pekko</groupId>
    <artifactId>pekko-stream_${scala.binary.version}</artifactId>
  </dependency>
</dependencies>
Gradle
def versions = [
  ScalaBinary: "2.13"
]
dependencies {
  implementation platform("org.apache.pekko:pekko-bom_${versions.ScalaBinary}:1.1.2+24-bcd44ee3-SNAPSHOT")

  implementation "org.apache.pekko:pekko-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 org.apache.pekko.Done;
import org.apache.pekko.NotUsed;
import org.apache.pekko.actor.ActorSystem;
import org.apache.pekko.actor.testkit.typed.javadsl.ManualTime;
import org.apache.pekko.actor.testkit.typed.javadsl.TestKitJunitResource;
import org.apache.pekko.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