`(cons ,head #'(lambda () ,tail)))
(defun pipe-tail (pipe)
- "Return tail of pipe or list, and destructively update
+ "Return tail of pipe or list, and destructively update
the tail if it is a function."
(if (functionp (rest pipe))
(setf (rest pipe) (funcall (rest pipe)))
(defun pipe-enumerate (pipe &key count key (result pipe))
"Go through all (or count) elements of pipe,
possibly applying the KEY function. (Try PRINT.)"
- ;; Returns RESULT, which defaults to the pipe itself.
+ ;; Returns RESULT, which defaults to the pipe itself.
(if (or (eq pipe +empty-pipe+) (eql count 0))
result
(progn
(if (eq pipe +empty-pipe+)
+empty-pipe+
(let ((head (pipe-head pipe))
- (tail (pipe-tail pipe)))
+ (tail (pipe-tail pipe)))
(if (funcall predicate head)
- (make-pipe head (pipe-filter predicate tail))
+ (make-pipe head (pipe-filter predicate tail))
(pipe-filter predicate tail)))))
-
+
(defun pipe-map (fn pipe)
"Map fn over pipe, delaying all but the first fn call."
(result (funcall fn head)))
(if (or (and filter-pred (funcall filter-pred result))
result)
- (make-pipe result (pipe-map-filtering fn tail filter-pred))
+ (make-pipe result (pipe-map-filtering fn tail filter-pred))
(pipe-map-filtering fn tail filter-pred)))))
-
+
(defun pipe-append (x y)
"Return a pipe that appends the elements of x and y."
(if (eq x +empty-pipe+)
(let ((x (funcall fn (pipe-head pipe))))
(make-pipe (pipe-head x)
(pipe-append (pipe-tail x)
- (pipe-mappend fn (pipe-tail pipe)))))))
+ (pipe-mappend fn (pipe-tail pipe)))))))
(defun pipe-mappend-filtering (fn pipe &optional filter-pred)
"Map fn over pipe, delaying all but the first fn call,
(result (funcall fn head)))
(if (or (and filter-pred (funcall filter-pred result))
result)
- (make-pipe (pipe-head result)
- (pipe-append (pipe-tail result)
- (pipe-mappend-filtering fn tail filter-pred)))
+ (make-pipe (pipe-head result)
+ (pipe-append (pipe-tail result)
+ (pipe-mappend-filtering fn tail filter-pred)))
(pipe-mappend-filtering fn tail filter-pred)))))