That sounds like a feature of questionable value, it's very easy to arrive at OOMEs with such a method.
On Sun, Nov 8, 2015 at 9:24 PM, <[email protected]> wrote: > I wasn't very clear in my original requirements. In the resulting Source, > I want its 1st element (i.e. its 1st sequence) to contain all the 1st > elements of the input sources; its 2nd sequence to contain all the 2nd > elements of the input sources; and so on until the shortest input source > ends. > > It's slipping my mind if this functionality has an analogue in the > standard library or I'm mislabeling it. > > I hope this clarifies what I'm talking about. > > > On Sunday, November 8, 2015 at 2:31:28 PM UTC-5, Giovanni Alberto > Caporaletti wrote: >> >> Why not just something like the following? >> >> val seqOfSources: Seq[Source[Int, Unit]] = Seq(List(1,2), List(3,4), >> List(5,6)).map(Source(_)) >> >> val sourceOfSeqs: Source[Seq[Int], Unit] = >> Source(seqOfSources.toList).flatMapConcat(identity).grouped(100) >> >> >> On Sunday, 8 November 2015 19:26:56 UTC+1, [email protected] wrote: >>> >>> Hello, >>> >>> I've been working on a way to turn a *Seq[Source[T]]* into >>> *Source[Seq[T]]* using Akka Streams 2.0. I believe I've succeeded, but >>> I'd like people to critique my code. Thanks in advance. >>> >>> object StreamUtils { >>> >>> def sequencedSource[T](sources: immutable.Seq[Source[T, Unit]]): >>> Source[immutable.Seq[T], Unit] = >>> Source.fromGraph(FlowGraph.create() { implicit builder => >>> import FlowGraph.Implicits._ >>> >>> val sequenceGraphStage = builder.add(new >>> SequenceGraphStage[T](sources.size)) >>> for ((source, index) <- sources.zipWithIndex) source ~> >>> sequenceGraphStage.in(index) >>> >>> SourceShape(sequenceGraphStage.out) >>> }) >>> >>> } >>> >>> class SequenceGraphStage[T](numInputs: Int) extends >>> GraphStage[UniformFanInShape[T, immutable.Seq[T]]] { >>> >>> require(numInputs > 0, "1 or more inputs required") >>> >>> val inputs = immutable.IndexedSeq.tabulate(numInputs)(num => >>> Inlet[T]("Sequence.in" + num)) >>> val output = Outlet[immutable.Seq[T]]("Sequence.out") >>> >>> override val shape = UniformFanInShape(output, inputs: _*) >>> >>> override def createLogic(inheritedAttributes: Attributes): >>> GraphStageLogic = new GraphStageLogic(shape) { >>> val elements = mutable.Buffer.empty[T] >>> >>> setHandler(output, new OutHandler { >>> override def onPull(): Unit = >>> inputs.foreach { input => >>> read(input) { element => >>> elements += element >>> >>> if (elements.size == inputs.size) { >>> push(output, elements.to[immutable.Seq]) >>> elements.clear() >>> } >>> } >>> } >>> }) >>> >>> inputs.foreach(setHandler(_, eagerTerminateInput)) >>> } >>> >>> override val toString = "Sequence" >>> >>> } >>> >>> >>> BTW, I did something similar in Streams 1.0 using FlexiMerge; the API >>> and boilerplate necessary was somewhat off-putting. I greatly appreciate >>> the cleanup in 2.0 so far. >>> >> -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: > http://doc.akka.io/docs/akka/current/additional/faq.html > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > -- Cheers, √ -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
