[akka-user] Re: how to define materialized value

2016-03-07 Thread Arun Sethia
Awesome thanks a lot. On Sunday, March 6, 2016 at 7:20:43 AM UTC-6, Rafał Krzewski wrote: > > Arun, > > a little correction: > > val runnableGraph = > source.viaMat(counter[Int])(Keep.right).toMat(sink)(Keep.both) > > And subsequently: > > val (counter, futureSum) = runnableGraph.run() > > Graph

[akka-user] Re: how to define materialized value

2016-03-06 Thread Rafał Krzewski
Arun, a little correction: val runnableGraph = source.viaMat(counter[Int])(Keep.right).toMat(sink)(Keep.both) And subsequently: val (counter, futureSum) = runnableGraph.run() Graph outlets are always streams. You need to connect them to a Sink (through intervening Flows or more complex Graph

[akka-user] Re: how to define materialized value

2016-03-05 Thread Arun Sethia
Thanks. I tried to put example using same: val source = Source (1 to 5).filter(x=> x%2==0) val sink:Sink[Int, Future[Int]]=Sink.fold[Int,Int](0)(_ + _) val runnableGraph = source.via(counter[Int]).toMat(sink)(Keep.left) val result=runnableGraph.run() def counter[T]: Flow[T, T, Counter] = {

[akka-user] Re: how to define materialized value

2016-03-05 Thread Arun Sethia
the given same code: val source = Source (1 to 5).filter(x=> x%2==0) val flow:Flow[Int,Int,Unit]=Flow[Int].map(x=> x * 2) val sink:Sink[Int, Future[Int]]=Sink.fold[Int,Int](0)(_ + _) val runnableGraph = source.via(flow).toMat(sink)(Keep.both) I am not sure what is use of using Keep.both vs Kee

[akka-user] Re: how to define materialized value

2016-03-05 Thread Arun Sethia
more Source[+Out, +Mat],Flow[-In, +Out, +Mat] and Sink[-In, +Mat] , in all cases what is +Mat type and how I can define one such , if possible any example will be great. On Saturday, March 5, 2016 at 6:02:56 PM UTC-6, Arun Sethia wrote: > > Hi, > > can some explain what does it mean of mater

[akka-user] Re: how to define materialized value

2016-03-05 Thread Arun Sethia
Thanks Rafal. Based on this I tried to make sample code, where I would like to count number of elements being processed and their sum: val source = Source (1 to 5).filter(x=> x%2==0) val sink:Sink[Int, Future[Int]]=Sink.fold[Int,Int](0)(_ + _) val runnableGraph = source.via(counter[Int]).toMat

[akka-user] Re: how to define materialized value

2016-03-05 Thread Rafał Krzewski
Hi, there are a few ways of doing that. Probably the simplest one is using Flow.mapMaterializedValue. Suppose you'd like to create a Flow that counts the elements that pass through it and makes the current count available through a "side channel": trait Counter { def get: Long } def