from

Stream the values of an Iterable.

Source operators

Signature

def from[O](iterable: java.lang.Iterable[O]): javadsl.Source[O, NotUsed]

Description

Stream the values of an Iterable. Make sure the Iterable is immutable or at least not modified after being used as a source. Otherwise the stream may fail with ConcurrentModificationException or other more subtle errors may occur.

emits the next value of the seq

completes when the last element of the seq has been emitted

Examples

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;

import akka.actor.ActorRef;
import akka.actor.Status.Success;
import akka.stream.OverflowStrategy;
import akka.stream.CompletionStrategy;
import akka.stream.javadsl.Sink;
import akka.testkit.TestProbe;

import java.util.Arrays;

final ActorSystem system = ActorSystem.create("SourceFromExample");
final Materializer materializer = ActorMaterializer.create(system);

Source<Integer, NotUsed> ints = Source.from(Arrays.asList(0, 1, 2, 3, 4, 5));
ints.runForeach(System.out::println, materializer);

String text =
    "Perfection is finally attained not when there is no longer more to add,"
        + "but when there is no longer anything to take away.";
Source<String, NotUsed> words = Source.from(Arrays.asList(text.split("\\s")));
words.runForeach(System.out::println, 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.