Reputation: 151
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?
Upvotes: 1
Views: 514
Reputation: 3965
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*)
Upvotes: 2