Questions tagged [scalaz-stream]

scalaz-stream is a streaming I/O library. The design goals are compositionality, expressiveness, resource safety, and speed. The design is meant to supersede or replace older iteratee or iteratee-style libraries.

The library supports a number of other interesting use cases:

  • Zipping and merging of streams: A streaming computations may read from multiple sources in a streaming fashion, zipping or merging their elements using a arbitrary Tee. In general, clients have a great deal of flexibility in what sort of topologies they can define--source, sinks, and effectful channels are all first-class concepts in the library.
  • Dynamic resource allocation: A streaming computation may allocate resources dynamically (for instance, reading a list of files to process from a stream built off a network socket), and the library will ensure these resources get released in the event of normal termination or when errors occur.
  • Nondeterministic and concurrent processing: A computation may read from multiple input streams simultaneously, using whichever result comes back first, and a pipeline of transformation can allow for nondeterminism and queueing at each stage.
  • Streaming parsing (UPCOMING): A separate layer handles constructing streaming parsers, for instance, for streaming JSON, XML, or binary parsing. See the roadmap for more information on this and other upcoming work.
83 questions
82
votes
1 answer

How do I replace a program written as a sequenced stream of state transitions with scalaz-stream?

I'm trying to understand how to reorganize a program which I would previously have written as a sequence of state transitions: I have some business logic: type In = Long type Count = Int type Out = Count type S = Map[Int, Count] val inputToIn:…
oxbow_lakes
  • 129,207
  • 53
  • 306
  • 443
48
votes
1 answer

Using Scalaz Stream for parsing task (replacing Scalaz Iteratees)

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…
Travis Brown
  • 135,682
  • 12
  • 352
  • 654
32
votes
2 answers

Scala streaming library differences (Reactive Streams/Iteratee/RxScala/Scalaz...)

I'm following the Functional Reactive Programming in Scala course on Coursera and we deal with RxScala Observables (based on RxJava). As far as I know, the Play Iteratee's library looks a bit like RxScala Observables, where Observables a bit like…
Sebastien Lorber
  • 79,294
  • 59
  • 260
  • 386
12
votes
1 answer

Scala fast text file read and upload to memory

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…
elm
  • 18,533
  • 11
  • 59
  • 106
11
votes
1 answer

Why do we need scalaz.stream over iteratee?

Recently, I've been playing with scalaz.iteratee and Play's iteratee. I think that iteratee is a great idea to provide modularity instead of the old imperative while loop -- the aim is to use a function as a handler of each new line instead of…
Xiaohe Dong
  • 4,503
  • 6
  • 19
  • 49
10
votes
1 answer

How to read from TCP and write to stdout?

I'm failing to get a simple scalaz-stream example running, reading from TCP and writing to std out. val src = tcp.reads(1024) val addr = new InetSocketAddress(12345) val p = tcp.server(addr, concurrentRequests = 1) { src ++…
Joe Kearney
  • 6,947
  • 5
  • 32
  • 42
8
votes
3 answers

Splitting a scalaz-stream process into two child streams

Using scalaz-stream is it possible to split/fork and then rejoin a stream? As an example, let's say I have the following function val streamOfNumbers : Process[Task,Int] = Process.emitAll(1 to 10) val sumOfEvenNumbers =…
James Davies
  • 9,224
  • 5
  • 36
  • 41
7
votes
3 answers

http4s - get request body as String or InputStream

I'm trying to define HttpService that receives json and parses it to case class with json4s library: import org.http4s._ import org.http4s.dsl._ import org.json4s._ import org.json4s.native.JsonMethods._ case class Request(firstName: String,…
mixel
  • 22,724
  • 10
  • 111
  • 154
7
votes
1 answer

How to convert Iterator to scalaz stream?

Suppose I've got an Iterator[A]. I would like to convert it to Process[Nothing, A] of scalaz stream. import scalaz.stream._ def foo[A](it: Iterator[A]): Process[Nothing, A] = ??? How would you implement foo ?
Michael
  • 37,415
  • 63
  • 167
  • 303
7
votes
1 answer

Merging scalaz-stream input processes seems to "wait" on stdin

I have a simple program: import scalaz._ import stream._ object Play extends App { val in1 = io.linesR("C:/tmp/as.txt") val in2 = io.linesR("C:/tmp/bs.txt") val p = (in1 merge in2) to io.stdOutLines p.run.run } The file as.txt contains…
oxbow_lakes
  • 129,207
  • 53
  • 306
  • 443
6
votes
1 answer

scalaz-stream: how to handle the "header" (first chunks) in a different way to the rest?

Context: I'm trying to write a Process1[ByteVector, spray.http.HttpResponsePart] with output ChunkedResponseStart(bytes), MessageChunk(bytes), MessageChunk(bytes), ..., ChunkedResponseEnd. I haven't yet fully wrapped my head around scalaz-stream…
Vasiliy Levykin
  • 202
  • 4
  • 6
6
votes
1 answer

Logging and ignoring exception from Task in scalaz-streams

Let's take an example from some scalaz-stream docs, but with a theoretical twist. import scalaz.stream._ import scalaz.concurrent.Task val converter: Task[Unit] = io.linesR("testdata/fahrenheit.txt") .filter(s => !s.trim.isEmpty &&…
kareblak
  • 412
  • 1
  • 3
  • 12
6
votes
1 answer

How to improve performance of code with Sink?

I have weird observation about scalaz-streams sinks. They are working slow. Does anyone know why is that? And is there any way to improve the performance? here are relevant parts of my code: version without sink //p is parameter with type p:…
user2963977
  • 562
  • 4
  • 16
6
votes
2 answers

Halting a Process[Task, O] on user input

I am trying to write the following function def haltOnUserInput[O](process: Process[Task, O]): Process[Task, O] which halts process when the user sends a line on stdin. In this scenario, it is ok to wait for the current computation in the process…
betehess
  • 817
  • 4
  • 18
6
votes
2 answers

Running scalaz-stream's Process gives could not find implicit value for parameter C: scalaz.Catchable[F2]?

Why am I getting the following error: could not find implicit value for parameter C: scalaz.Catchable[F2] when executing P(1,2,3).run? [scalaz-stream-sandbox]> console [info] Starting scala interpreter... [info] import scalaz.stream._ import…
Jacek Laskowski
  • 64,943
  • 20
  • 207
  • 364
1
2 3 4 5 6