Skip to content

Commit 85f6ff8

Browse files
committed
jupyter-org--coalesce-stream-results: Refactor
1 parent bc3b78b commit 85f6ff8

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

jupyter-org-client.el

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,28 +1596,20 @@ the return value for asynchronous Jupyter source blocks in
15961596
"Return RESULTS with all contiguous stream results concatenated.
15971597
All stream results are then turned into fixed-width or
15981598
example-block elements."
1599-
(let ((head-to-scalar
1600-
(lambda (a)
1601-
;; Convert the head element of A to a scalar if its a
1602-
;; stream result, return A.
1603-
(when (jupyter-org--stream-result-p (car a))
1604-
(setcar a (jupyter-org-scalar
1605-
(jupyter-org-strip-last-newline
1606-
(car a)))))
1607-
a)))
1608-
(nreverse
1609-
(funcall
1610-
head-to-scalar
1611-
(cl-reduce
1612-
(lambda (a b)
1613-
(if (and (jupyter-org--stream-result-p b)
1614-
(jupyter-org--stream-result-p (car a)))
1615-
(setcar a (concat (car a) b))
1616-
(funcall head-to-scalar a)
1617-
(push b a))
1618-
a)
1619-
results
1620-
:initial-value nil)))))
1599+
(cl-labels ((scalar (s) (jupyter-org-scalar
1600+
(jupyter-org-strip-last-newline s))))
1601+
(let (lst str)
1602+
(while (consp results)
1603+
(let ((value (pop results)))
1604+
(if (jupyter-org--stream-result-p value)
1605+
(cl-callf concat str value)
1606+
(when str
1607+
(push (scalar str) lst)
1608+
(setq str nil))
1609+
(push value lst))))
1610+
(when str
1611+
(push (scalar str) lst))
1612+
(nreverse lst))))
16211613

16221614
(defun jupyter-org--process-pandoc-results (results)
16231615
(let* ((results (copy-sequence results))

0 commit comments

Comments
 (0)