Collecting sink materialized values as source

313 views Asked by At

Is there a better way (ie. by removing the Materializer constraint) to implement the following method:

import akka.NotUsed
import akka.stream.Materializer
import akka.stream.scaladsl.{Keep, Sink, Source}

def assemble[A, B, C](source: Source[A, NotUsed])
                     (f: A => Source[B, NotUsed], g: A => Sink[B, C])
                     (implicit m: Materializer): Source[C, NotUsed] = {

  source.map(a => f(a).toMat(g(a))(Keep.right).run())
}

?

1

There are 1 answers

0
Stefano Bonetti On BEST ANSWER

Essentially you are after materializing a bunch of graphs and create a Source of their materialized values. I don't see a way of doing this without a Materializer parameter.

In case it helps, you can write your method in a more compact fashion as

source.map(a => f(a).runWith(g(a)))