[akka-stream] Concatenate multiple Sources while preserving materialized values

448 views
Skip to first unread message

Arron Norwell

unread,
Jun 23, 2016, 2:55:11 PM6/23/16
to Akka User List
Hi,

I'm looking for a good way to concatenate sources while preserving materialized values. For example, If I have 
val source1: Source[T,Mat] = _
val source2
: Source[T,akka.NotUsed] = _
I would like to be able to preserve the first materialized value (and possibly more generally, support other means of combination), e.g.:


val concatSource
: Source[T, Mat] = Source.combine(source1, source2)(Concat[T]())


It seems difficult to get this to work, because concat discards materialized values. Is there a good way to approach this?

Arron Norwell

unread,
Jun 23, 2016, 3:06:57 PM6/23/16
to Akka User List
Sorry, this is actually supported and very straightforward. Solution is:

//most common Keep.left case
source1
.concat(source2)

//more general
source1
.concatMat(source2)(Keep.both) //or whatever strategy
Reply all
Reply to author
Forward
0 new messages