Streams

A stream is generally a lazy and linear sequence collection. Stream elements are evaluated only when needed. Streams are already defined in Scala and Clojure. Since elements of a stream are evaluated lazily, it can be of infinite length. In this section, we will explore streams in Scala and Clojure. Let me start with stream in Scala. List, which we are going to explore in the coming chapter, differs from stream only in lazy computation. Other properties of list are similar to stream.

Stream in Scala

Stream is a class defined in Scala. Stream constructor can be used to create Stream object. Stream elements are evaluated when they are required. Stream-calculated values are cached so that they can be used further. Let us explorer the characteristics ...

Get Learning Functional Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.