akka stream toMat

Viewed 6101

I am trying to understand what does toMat in akka streaming. For example:

val sink1:Sink[Int, Future[Int]]=Sink.fold[Int,Int](0)(_ + _)

val flow=Flow[Int].fold[Int](0){(x,y)=> x+y}

val runnable = Source (1 to 10).viaMat(flow)(Keep.right).toMat(sink1)(Keep.both)
  1. what is use of viaMat vs via?
  2. what is toMat is doing between viaMat to toMat?
  3. what is use of keep.both, does it mean I can have value materialized from previous and the current one if yes then how I can get those values back.

Thanks Arun

2 Answers
Related