Source.applySource.from

Stream the values of an immutable.SeqIterable.

Source operators

Signature

Description

Stream the values of an immutable.SeqIterable. 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.

Examples

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;

import org.apache.pekko.actor.ActorRef;
import org.apache.pekko.stream.OverflowStrategy;
import org.apache.pekko.stream.CompletionStrategy;
import org.apache.pekko.stream.javadsl.Sink;
import org.apache.pekko.testkit.TestProbe;

import org.apache.pekko.stream.javadsl.RunnableGraph;
import java.util.concurrent.CompletableFuture;

import java.util.Arrays;
import java.util.Optional;

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

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, system);

Reactive Streams semantics

emits the next value of the seq

completes when the last element of the seq has been emitted