diff --git a/akka-docs/src/main/paradox/stream/operators/Source/from.md b/akka-docs/src/main/paradox/stream/operators/Source/from.md index cfc6858d2f..6f56423ca8 100644 --- a/akka-docs/src/main/paradox/stream/operators/Source/from.md +++ b/akka-docs/src/main/paradox/stream/operators/Source/from.md @@ -4,10 +4,19 @@ Stream the values of an `Iterable`. @ref[Source operators](../index.md#source-operators) + +@@@div { .group-scala } + +## Signature + +@@signature [Source.scala]($akka$/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala) { #from } + +@@@ + ## Description Stream the values of an `Iterable`. Make sure the `Iterable` is immutable or at least not modified after being used -as a source. +as a source. Otherwise the stream may fail with `ConcurrentModificationException` or other more subtle errors may occur. @@@div { .callout } @@ -17,3 +26,8 @@ as a source. @@@ + +## Examples + +Java +: @@snip [from.java]($akka$/akka-docs/src/test/java/jdocs/stream/operators/SourceDocExamples.java) { #imports #source-from-example } diff --git a/akka-docs/src/test/java/jdocs/stream/operators/SourceDocExamples.java b/akka-docs/src/test/java/jdocs/stream/operators/SourceDocExamples.java new file mode 100644 index 0000000000..e13bc9dfa3 --- /dev/null +++ b/akka-docs/src/test/java/jdocs/stream/operators/SourceDocExamples.java @@ -0,0 +1,35 @@ +/** + * Copyright (C) 2018 Lightbend Inc. + */ + +package jdocs.stream.operators; + +//#imports +import akka.NotUsed; +import akka.actor.ActorSystem; +import akka.stream.ActorMaterializer; +import akka.stream.Materializer; +import akka.stream.javadsl.Source; + +import java.util.Arrays; + +//#imports + +public class SourceDocExamples { + + public static void fromExample() { + //#source-from-example + final ActorSystem system = ActorSystem.create("SourceFromExample"); + final Materializer materializer = ActorMaterializer.create(system); + + Source 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 words = Source.from(Arrays.asList(text.split("\\s"))); + words.runForeach(System.out::println, materializer); + //#source-from-example + } + +}