1
votes

Let's say I have a string "sky is blue" and inside flow I divide it into several elements I would like to propagate down the graph.

Source.single("only one element")
  .via(Flow.fromFunction(string => string.split(" ").toSeq))
  .map(*do something for each word*)

In this code the Flow has type Flow[String, Seq[String, NotUsed], which makes sense as Flows must have exactly one output.

Is there any Akka Streams mechanism to solve that problem?

1

1 Answers

2
votes

If I understand correctly, you want each chunk of the string to be an individual element in the stream. This can be done using mapConcat:

Source.single("only one element")
  .mapConcat { string =>
    string.split(" ")
  }
  .map(*do something for each word*)