Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stream in production code

Tags:

scala

Do people really use Scala's Stream class in production code, or is it primarily of academic interest?

like image 971
Eric Bowman - abstracto - Avatar asked Mar 19 '11 15:03

Eric Bowman - abstracto -


People also ask

What does stream code mean?

Noun. codestream (plural codestreams) (computing) A stream of code. The codestream obtained after compression of an image with JPEG 2000 is scalable in nature, meaning that it can be decoded in a number of ways.

What is stream () in Java?

A stream consists of source followed by zero or more intermediate methods combined together (pipelined) and a terminal method to process the objects obtained from the source as per the methods described. Stream is used to compute elements as per the pipelined methods without altering the original value of the object.

What is stream concept?

A stream is a flow of data from a program to a backing store, or from a backing store to a program. The program can either write to a stream, or read from a stream. Reading from and writing to a stream. Streams and stream processing.

What is a stream object?

A stream is an object which accepts sequences of characters. It is a destination of data which can be thought of much like an output stream in C++ or an ANSI C-file stream for writing data to a disk or another peripheral device.


2 Answers

There's no problem with Stream, except when people use it to replace Iterator -- as opposed to replacing List, which is the collection most similar to it. In that particular case, one has to be careful in its use. On the other hand, one has to be careful using Iterator as well, since each element can only be iterated through once.

So, since both have their own problems, why single out Stream's? I daresay it's simply that people are used to Iterator from Java, whereas Stream is a functional thing.

like image 169
Daniel C. Sobral Avatar answered Sep 30 '22 12:09

Daniel C. Sobral


Even though I wrote that Iterator is what I want to use nearly all the time I do use Stream in production code. I just don't automatically assume that the cells are garbage collected.

Sometimes Stream fits the problem perfectly. I think the api gives some good examples where recursion is involved...

like image 34
huynhjl Avatar answered Sep 30 '22 12:09

huynhjl