scalaz-stream

Using Scalaz Stream for parsing task (replacing Scalaz Iteratees)

房东的猫 提交于 2019-12-29 10:09:03
问题 Introduction I use Scalaz 7's iteratees in a number of projects, primarily for processing large-ish files. I'd like to start switching to Scalaz streams, which are designed to replace the iteratee package (which frankly is missing a lot of pieces and is kind of a pain to use). Streams are based on machines (another variation on the iteratee idea), which have also been implemented in Haskell. I've used the Haskell machines library a bit, but the relationship between machines and streams isn't

Using Scalaz Stream for parsing task (replacing Scalaz Iteratees)

允我心安 提交于 2019-12-29 10:08:33
问题 Introduction I use Scalaz 7's iteratees in a number of projects, primarily for processing large-ish files. I'd like to start switching to Scalaz streams, which are designed to replace the iteratee package (which frankly is missing a lot of pieces and is kind of a pain to use). Streams are based on machines (another variation on the iteratee idea), which have also been implemented in Haskell. I've used the Haskell machines library a bit, but the relationship between machines and streams isn't

Why awakeEvery was removed from scalaz-stream

一世执手 提交于 2019-12-24 12:44:05
问题 I found that there is no more awakeEvery inside scalaz.stream.Process in modern scalaz-stream. How to run something with period then? 回答1: It was moved to the scalaz.stream.time package: import scalaz.stream._ scala> implicit val sc = new java.util.concurrent.ScheduledThreadPoolExecutor(1) sc: java.util.concurrent.ScheduledThreadPoolExecutor = java.util.concurrent.ScheduledThreadPoolExecutor@6b9013a5[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0] scala>

Scala fast text file read and upload to memory

让人想犯罪 __ 提交于 2019-12-08 23:40:34
问题 In Scala, for reading a text file and uploading it into an array, a common approach is scala.io.Source.fromFile("file.txt").getLines.toArray Especially for very large files, is there a faster approach perhaps by reading blocks of bytes into memory first and then splitting them by new line characters ? (See Read entire file in Scala for commonly used approaches.) Many Thanks. 回答1: The performance problem has nothing to do with the way the data is read. It is already buffered. Nothing happens

How to merge adjacent lines with scalaz-stream without losing the splitting line

六月ゝ 毕业季﹏ 提交于 2019-12-07 19:44:28
问题 Suppose that my input file myInput.txt looks as follows: ~~~ text1 bla bla some more text ~~~ text2 lorem ipsum ~~~ othertext the wikipedia entry is not up to date That is, there are documents separated by ~~~ . The desired output is as follows: text1: bla bla some more text text2: lorem ipsum othertext: the wikipedia entry is not up to date How do I go about that? The following seems pretty unnatural, plus I lose the titles: val converter: Task[Unit] = io.linesR("myInput.txt") .split(line =>

How to merge adjacent lines with scalaz-stream without losing the splitting line

梦想的初衷 提交于 2019-12-06 13:42:12
Suppose that my input file myInput.txt looks as follows: ~~~ text1 bla bla some more text ~~~ text2 lorem ipsum ~~~ othertext the wikipedia entry is not up to date That is, there are documents separated by ~~~ . The desired output is as follows: text1: bla bla some more text text2: lorem ipsum othertext: the wikipedia entry is not up to date How do I go about that? The following seems pretty unnatural, plus I lose the titles: val converter: Task[Unit] = io.linesR("myInput.txt") .split(line => line.startsWith("~~~")) .intersperse(Vector("\nNew document: ")) .map(vec => vec.mkString(" ")) .pipe

Scala fast text file read and upload to memory

本秂侑毒 提交于 2019-11-30 12:23:43
In Scala, for reading a text file and uploading it into an array, a common approach is scala.io.Source.fromFile("file.txt").getLines.toArray Especially for very large files, is there a faster approach perhaps by reading blocks of bytes into memory first and then splitting them by new line characters ? (See Read entire file in Scala for commonly used approaches.) Many Thanks. The performance problem has nothing to do with the way the data is read. It is already buffered. Nothing happens until you actually iterate through the lines: // measures time taken by enclosed code def timed[A](block: =>