branch: externals/stream
commit daa19594e7058ae531ec611b067fb970353b0e7c
Author: Earl Hyatt <[email protected]>
Commit: Stefan Monnier <[email protected]>
Add generalized variables for streams that error when used.
* stream.el (seq-elt, stream-first, stream-rest): Signal an error when
trying to
use this function as a place for 'setf'.
---
stream.el | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/stream.el b/stream.el
index 300f3b8ae2..dea42b4962 100644
--- a/stream.el
+++ b/stream.el
@@ -290,6 +290,10 @@ range is infinite."
Return nil if STREAM is empty."
(stream--first (stream--force stream)))
+(defun \(setf\ stream-first\) (_store _stream)
+ "Signal an error when trying to use `setf' on the head of a stream."
+ (error "Streams are not mutable"))
+
(defun stream-rest (stream)
"Return a stream of all but the first element of STREAM."
(setq stream (stream--force stream))
@@ -297,6 +301,10 @@ Return nil if STREAM is empty."
(stream-empty)
(stream--rest stream)))
+(defun \(setf\ stream-rest\) (_store _stream)
+ "Signal an error when trying to use `setf' on the tail of a stream."
+ (error "Streams are not mutable"))
+
(defun stream-append (&rest streams)
"Concatenate the STREAMS.
Requesting elements from the resulting stream will request the
@@ -337,6 +345,9 @@ elements in the STREAMS in order."
(setq n (1- n)))
(stream-first stream))
+(cl-defmethod (setf seq-elt) (_store (_sequence stream) _n)
+ (error "Streams are not mutable"))
+
(cl-defmethod seq-length ((stream stream))
"Return the length of STREAM.
This function will eagerly consume the entire stream."