Add combinedMat method to Source (#23809)

* Add combinedMat method to Source

* Fix formatting
This commit is contained in:
Richard Imaoka 2017-11-02 10:34:40 +09:00 committed by Konrad `ktoso` Malawski
parent 0988933fac
commit a50df1c575
4 changed files with 87 additions and 0 deletions

View file

@ -448,6 +448,19 @@ object Source {
combineRest(2, rest.iterator)
})
/**
* Combines two sources with fan-in strategy like `Merge` or `Concat` and returns `Source` with a materialized value.
*/
def combineMat[T, U, M1, M2, M](first: Source[T, M1], second: Source[T, M2])(strategy: Int Graph[UniformFanInShape[T, U], NotUsed])(matF: (M1, M2) M): Source[U, M] = {
val secondPartiallyCombined = GraphDSL.create(second) { implicit b secondShape
import GraphDSL.Implicits._
val c = b.add(strategy(2))
secondShape ~> c.in(1)
FlowShape(c.in(0), c.out)
}
first.viaMat(secondPartiallyCombined)(matF)
}
/**
* Combine the elements of multiple streams into a stream of sequences.
*/