What are streams? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What are streams?

I am kind of confused of that term...I hear it every now and then but have little knowledge of it.From what i know its like a small storage where data are stored before any operation...Am i correct ?

9th Feb 2018, 11:32 AM
3D CrackerJack
3D CrackerJack - avatar
3 Answers
+ 2
A stream is an object that you can ask for the next x elements. If your stream is infinite, like the stream of all natural numbers, then you cannot store all of them in memory, because your memory is finite. But the natural numbers have a very simple rule: Start with 0; add +1 each time. So when I want the 50 naturals, the stream can deliver those. So infinite streams require a clear rule to generate the next member. A finite stream is like a list or an array. You can enumerate all the members. Or you use a generation rule that ends somehow. That's why I said streams abstract over lists and generators.
10th Feb 2018, 6:12 AM
1of3
1of3 - avatar
+ 2
Sorry but don't know about lists.....and What are infinite streams then...?
9th Feb 2018, 9:10 PM
3D CrackerJack
3D CrackerJack - avatar
+ 1
A stream is an abstraction over lists and generators. Lists you probably know. Generators produce results upon request, like a generator for all prime numbers. So you can ask a stream for x results. Streams can be finite or infinite. The concept is thus very flexible.
9th Feb 2018, 12:50 PM
1of3
1of3 - avatar