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 Saturday, March 5, 2016 at 7:41:18 PM UTC+3, Giovanni Alberto Caporaletti wrote: > > 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, Future[U]] = { > Flow[T] > .fold(Future.successful(zero))((fu, t) => fu.flatMap(f(_, t))) > .mapAsync(1)(identity) > .toMat(Sink.head)(Keep.right) > } > > > > On Saturday, 5 March 2016 17:00:08 UTC+1, Andrew Gaydenko wrote: >> >> Hi! There is >> >> f: (U, T) ⇒ Future[U] >> >> rather than >> >> f: (U, T) ⇒ U >> >> in hands. How to create >> >> Sink[T, Future[U]] >> >> ? >> > -- >>>>>>>>>> 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 --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.