Source.single

Stream a single object

Source operators

Signature

def single[T](element: T): Source[T, NotUsed]

Description

Stream a single object

emits the value once

completes when the single value has been emitted

Examples

Scala
import akka.stream._

val s: Future[immutable.Seq[Int]] = Source.single(1).runWith(Sink.seq)
s.foreach(list ⇒ println(s"Collected elements: $list")) // prints: Collected elements: List(1)
Java
import akka.stream.*;

CompletionStage<List<String>> future = Source.single("A").runWith(Sink.seq(), materializer);
CompletableFuture<List<String>> completableFuture = future.toCompletableFuture();
completableFuture.thenAccept(result -> System.out.printf("collected elements: %s\n", result));
// result list will contain exactly one element "A"
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.