[akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-15 Thread Andrew Gaydenko
Giovanni, hi! With some piece of stubbornness :) I (guess) have found a way with Source.last(): def sinkFoldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]] = Sink.fromGraph { val last = Sink.last[U] GraphDSL.create(last) { implicit b => last => import

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-09 Thread Andrew Gaydenko
On Wednesday, March 9, 2016 at 1:20:37 PM UTC+3, Giovanni Alberto Caporaletti wrote: > > It would fail with an empty stream. You can use lastOption but you would > need to map over the materialized value thus needing an execution context > outside the stream context. > Oh.. Yes! Thanks for

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-09 Thread Giovanni Alberto Caporaletti
It would fail with an empty stream. You can use lastOption but you would need to map over the materialized value thus needing an execution context outside the stream context. cheers G On Wednesday, 9 March 2016 01:19:01 UTC+1, Andrew Gaydenko wrote: > > Giovanni, I mean your last suggestion

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-08 Thread Andrew Gaydenko
Giovanni, I mean your last suggestion with custom stage. -- >> Read the docs: http://akka.io/docs/ >> Check the FAQ: >> http://doc.akka.io/docs/akka/current/additional/faq.html >> Search the archives: https://groups.google.com/group/akka-user ---

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-08 Thread Andrew Gaydenko
Giovanni, hi! What do you think about replacing val sink = Sink.fold(zero)(Keep.right[U, U]) with val sink = Sink.last[U] ? -- >> Read the docs: http://akka.io/docs/ >> Check the FAQ: >> http://doc.akka.io/docs/akka/current/additional/faq.html

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-08 Thread Viktor Klang
I'll volunteer to review :) On Tue, Mar 8, 2016 at 12:26 PM, Konrad Malawski wrote: > Here's the ticket, you'd like to contribute these operations (it's pretty > easy to contribute, one can look at mapAsync and see how it differs from > map): >

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-08 Thread Viktor Klang
I'd like to repeat that a scanAsync and a foldAsync would be very welcome additions :) On Tue, Mar 8, 2016 at 12:01 AM, Andrew Gaydenko wrote: > Giovanni, hi! > > Thanks! - have played with this test. In fact, I started tests with > -Xmx=128M, and range up to 20M. The

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-07 Thread Andrew Gaydenko
Giovanni, hi! Thanks! - have played with this test. In fact, I started tests with -Xmx=128M, and range up to 20M. The first two variants resulted in OOME, as Roland predicted, and the last one with own Graph resulted in the rather quick answer with small RAM footprint during execution (~100MB

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-07 Thread Giovanni Alberto Caporaletti
def foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]] = { Sink.fold[Future[U], T](Future.successful(zero)) { (fu, t) => println(s"inside fold $t") fu.flatMap { x => println(s"inside flatMap $x") f(x, t) } }.mapMaterializedValue(_ flatMap identity) } val

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-07 Thread Andrew Gaydenko
On Sunday, March 6, 2016 at 2:28:22 AM UTC+3, Giovanni Alberto Caporaletti wrote: > > Hi Roland, > you're right, my solution was a bit naive. I came up with this, I'm pretty > sure it can be done in a better way, looking forward to seeing your > solution :) > Giovanni, thanks for this graph -

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-05 Thread Giovanni Alberto Caporaletti
Hi Roland, you're right, my solution was a bit naive. I came up with this, I'm pretty sure it can be done in a better way, looking forward to seeing your solution :) def foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]] = Sink.fromGraph { val sink =

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-05 Thread Andrew Gaydenko
On Saturday, March 5, 2016 at 11:52:06 PM UTC+3, rkuhn wrote: > > Unfortunately these solutions create unbounded amounts of futures without > back pressure, so I'd recommend against this approach. But it is late and > I'm on the phone so cannot suggest a proper solution. > Roland, hi! Thanks

Re: [akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-05 Thread Roland Kuhn
Unfortunately these solutions create unbounded amounts of futures without back pressure, so I'd recommend against this approach. But it is late and I'm on the phone so cannot suggest a proper solution. Regards, Roland Sent from my iPhone > On 05 Mar 2016, at 17:41, Giovanni Alberto

[akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-05 Thread Andrew Gaydenko
Giovanni, hi! I used a way similar to the the first suggestion, but wasn't sure it is elegant way to wrap zero into Future on rewriting folding function. So, I'll experiment with both ways when some benchmarks be ready. And I need some time to dig in the second suggestion :) Thanks!! On

[akka-user] Re: How to? - Sink.foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]

2016-03-05 Thread Giovanni Alberto Caporaletti
how about this: def foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]] = { Sink .fold[Future[U], T](Future.successful(zero))((fu, t) => fu.flatMap(f(_, t))) .mapMaterializedValue(_ flatMap identity) } or this: def foldM[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T,