=str Clean up Source#combine instance method code. (#31188)

This commit is contained in:
kerr 2022-03-10 20:52:33 +08:00 committed by GitHub
parent 042c25c9b2
commit f6e73fa5ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -231,20 +231,7 @@ final class Source[+Out, +Mat](
@deprecated("Use `Source.combine` on companion object instead", "2.5.5")
def combine[T, U](first: Source[T, _], second: Source[T, _], rest: Source[T, _]*)(
strategy: Int => Graph[UniformFanInShape[T, U], NotUsed]): Source[U, NotUsed] =
Source.fromGraph(GraphDSL.create() { implicit b =>
import GraphDSL.Implicits._
val c = b.add(strategy(rest.size + 2))
first ~> c.in(0)
second ~> c.in(1)
@tailrec def combineRest(idx: Int, i: Iterator[Source[T, _]]): SourceShape[U] =
if (i.hasNext) {
i.next() ~> c.in(idx)
combineRest(idx + 1, i)
} else SourceShape(c.out)
combineRest(2, rest.iterator)
})
Source.combine(first, second, rest: _*)(strategy)
/**
* Transform this source whose element is ``e`` into a source producing tuple ``(e, f(e))``