Hi Gilad,

On Thu, Nov 26, 2015 at 1:56 PM, Gilad Hoch <[email protected]> wrote:

> Hi,
>
> I'm thinking of migrating some code I have written with play's iteratees
> module, to akka-stream.
> I'm lacking many useful constructs iteratees have, e.g unfold & unfoldM
> generators.
>
> Iv'e tried doing something naive at first:
>
> def unfold[S,E](s: S)(f: S => Option[(S,E)]): Source[E,Unit] =
>     Source(() => Iterator.iterate(f(s))(opt => f(opt.get._1)))
>       .map(_.get._2)
>
> def unfoldM[S,E](s: S)(g: S => Future[Option[(S,E)]])(implicit ec:
> ExecutionContext): Source[E,Unit] =
>     Source(() => Iterator.iterate(g(s))(_.flatMap(opt => g(opt.get._1))))
>       .mapAsync(1)(_.map(_.get._2))
>
> but it didn't worked very well (don't know why).
>

Can you give us a testcase that fails with the above? There should be no
problem implementing these signatures (apart from that your above code does
not handle the Option and therefore does not stop).


> so I implemented it using actorPublisher instead.
>
> code can be found at this gist:
> https://gist.github.com/hochgi/cbe5ffc6cf2915e31091
>
> this seems to work fine, and it wasn't too hard to implement,
> so it raises some questions.
>

Hmm, for these tasks, if the build in operations are not good enough you
are better of creating a custom stage:
http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0-M1/scala/stream-customize.html#custom-linear-processing-stages

That does not work yet with asynchronous processing (futures in your case)
but that will be possible with the new GraphStages which I am documenting
right now.


>
> 1. I may think the implementation is good, but is it? I'm no expert...
> 2. if it is so trivial, why it's not in the official API? I think it
> should be part of the API.
>

Because
 - we can't come up with all the possible combinators people might ever
need. Open a ticket if you feel something is missing, and then we consider
it for inclusion
 - we are very conservative about adding combinators to avoid building a
kitchen sink. I understand it feels better to have a one-liner for
everything, but Akka Streams is very extensible (more and more every day)
and in the long term that is what matters because no framework can provide
all the operators that people will ever need. That said, unfold is one nice
addition, so please open a ticket.

-Endre


> especially since I'm probably not the only one migrating iteratees code to
> akka streams...
>
> thanks,
> Gilad.
>
> --
> >>>>>>>>>> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to