Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a view and a stream?

Tags:

In the Scala 2.8 collections framework, what is the difference between view and toStream?

like image 388
Craig P. Motlin Avatar asked Feb 17 '10 17:02

Craig P. Motlin


People also ask

Is watching YouTube considered streaming?

Streamed video content can include movies, TV shows, YouTube videos and livestreamed content. Services such as Netflix and Hulu have had great success in streaming videos to subscribers. The term streaming refers to the continual transmission of audio and video files from a server to a client.

What is a stream view?

Views: The total number of times a live stream was viewed while live. New Subscribers: The number of users who subscribed to your channel during the stream. Total watch time: The total time the event was played across all views. Peak concurrents: The highest number of views during the stream.

What is the difference between in stream and in feed?

The main difference between Newsfeed Video ads and In-Stream Video ads is that newsfeed video ads are standalone ads that appear in users' newsfeeds, rather than within another video. In-stream ads are embedded in another piece of video content. In addition, in-stream ads require sound, while newsfeed ads do not.

What is the difference between playing and streaming?

If a video file is downloaded, a copy of the entire file is saved onto a device's hard drive, and the video cannot play until the entire file finishes downloading. If it's streamed instead, the browser plays the video without actually copying and saving it.


1 Answers

In a view elements are recomputed each time they are accessed. In a stream elements are retained as they are evaluated.

For example:

val doubled = List(1,2,3,4,5,6,7,8,9,10).view.map(_*2) println(doubled.mkString(" ")) println(doubled.mkString(" ")) 

will re-evaluate the map for each element twice. Once for the first println, and again for the second. In contrast

val doubled = List(1,2,3,4,5,6,7,8,9,10).toStream.map(_*2) println(doubled.mkString(" ")) println(doubled.mkString(" ")) 

will only double the elements once.

A view is like a recipe to create a collection. When you ask for elements of a view it carries out the recipe each time.

A stream is like a guy with a bunch of dry-erase cards. The guy knows how to compute subsequent elements of the collection. You can ask him for the next element of the collection and gives you a card with the element written on it and a string tied from the card to his finger (to help him remember). Also, before he gives you a card he unties the first string from his finger and ties it to the new card.

If you hold onto the first card (i.e. keep a reference to the head of the stream) you might eventually run out of cards (i.e. memory) when you ask for the next element, but if you don't need to go back to the first elements you can cut the string and hand the unneeded cards back to the guy and he can re-use them (they're dry-erase afterall). This is how a stream can represent an infinite sequence without running out of memory.

like image 154
Geoff Reedy Avatar answered Sep 18 '22 13:09

Geoff Reedy