Source.range
Emit each integer in a range, with an option to take bigger steps than 1.
Dependency
- sbt
val AkkaVersion = "2.6.21" libraryDependencies += "com.typesafe.akka" %% "akka-stream" % AkkaVersion
- Maven
- Gradle
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
-
source
import 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.
Reactive Streams semantics
emits when there is demand, the next value
completes when the end of the range has been reached