1

Recently I started using scalaz streams in Scala/Akka. I'm fetching records from a nosql database. I want to map records to message items (via translateItem: Item) and create Packages (1 Package = 100 Items) of them. E.g. there are 500 records.

 val readChunks = records.chunk(100)
 val createPackages = readChunks.map(chunk => translateItem(chunk))
                                .map(i => toPackage(i))
 val result = createPackages.runLog.run.toList

I've tried to fetch the result (the List[Package]) via runLog. The output of the log looks good. But I don't need the logging overhead.

But how to write the result to a list e.g.?

Or I might return a Future[List[Package]] and pass it to an Akka actor to fetch (Await.result) it. I might convert the scalaz Task to a Future.

Thanks in advance.

Marco Mayer
  • 197
  • 2
  • 10
  • 1
    The "Log" in `runLog` just means that the outputs are collected—it doesn't have much to do with _logging_ in the record keeping sense. You could write a version of `runLog` that collects the outputs into a list, but the performance is going to suffer. If you really want a list, consider `runLog.map(_.toList)`, which gives you a `Task[List[Package]]` that you can convert into a `Future[List[Package]]`. – Travis Brown Mar 05 '15 at 17:32

0 Answers0