jupyter-org--coalesce-stream-results: Refactor

This commit is contained in:
Nathaniel Nicandro 2023-02-10 23:09:42 -06:00
parent bc3b78be43
commit 85f6ff84ed

View file

@ -1596,28 +1596,20 @@ the return value for asynchronous Jupyter source blocks in
"Return RESULTS with all contiguous stream results concatenated. "Return RESULTS with all contiguous stream results concatenated.
All stream results are then turned into fixed-width or All stream results are then turned into fixed-width or
example-block elements." example-block elements."
(let ((head-to-scalar (cl-labels ((scalar (s) (jupyter-org-scalar
(lambda (a) (jupyter-org-strip-last-newline s))))
;; Convert the head element of A to a scalar if its a (let (lst str)
;; stream result, return A. (while (consp results)
(when (jupyter-org--stream-result-p (car a)) (let ((value (pop results)))
(setcar a (jupyter-org-scalar (if (jupyter-org--stream-result-p value)
(jupyter-org-strip-last-newline (cl-callf concat str value)
(car a))))) (when str
a))) (push (scalar str) lst)
(nreverse (setq str nil))
(funcall (push value lst))))
head-to-scalar (when str
(cl-reduce (push (scalar str) lst))
(lambda (a b) (nreverse lst))))
(if (and (jupyter-org--stream-result-p b)
(jupyter-org--stream-result-p (car a)))
(setcar a (concat (car a) b))
(funcall head-to-scalar a)
(push b a))
a)
results
:initial-value nil)))))
(defun jupyter-org--process-pandoc-results (results) (defun jupyter-org--process-pandoc-results (results)
(let* ((results (copy-sequence results)) (let* ((results (copy-sequence results))