Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Is the stream produced by stream lazy the same as stream expr?


Asked by Valentin Pope on Dec 12, 2021 FAQ



The stream produced by stream-lazy has the same content as the stream produced by stream-expr; that is, operations like stream-first on the result stream will force stream-expr and retry on its result.
Thereof,
Streams are lazy because intermediate operations are not evaluated unless terminal operation is invoked. Each intermediate operation creates a new stream, stores the provided operation/function and return the new stream. The pipeline accumulates these newly created streams.
Next, A stream is a kind of sequence that supports functional iteration via stream-first and stream-rest. The stream-cons form constructs a lazy stream, but plain lists can be used as streams, and functions such as in-range and in-naturals also create streams.
One may also ask,
They are always lazy; executing an intermediate operation such as filter() does not actually perform any filtering, but instead creates a new stream that, when traversed, contains the elements of the initial stream that match the given predicate.
In respect to this,
The first element of the stream as produced by first-expr must be a single value. The rest-expr must produce a stream when it is evaluated, otherwise the exn:fail:contract? exception is raised. Changed in version 8.0.0.12 of package base: Added #:eager options.