Skip to content

Instantly share code, notes, and snippets.

@tatut
Created January 18, 2023 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatut/a0f4a88f3a86a030802b3ab2893e3b06 to your computer and use it in GitHub Desktop.
Save tatut/a0f4a88f3a86a030802b3ab2893e3b06 to your computer and use it in GitHub Desktop.
hack cider orchard.inspect/render-indexed-values to render a table
(defn render-indexed-values
([inspector obj] (render-indexed-values inspector obj 0))
([inspector obj idx-starts-from]
(if (every? map? obj)
;; Print table instead
(let [[_ header1 header2 & rows] (clojure.string/split-lines
(with-out-str
(clojure.pprint/print-table obj)))]
(loop [{counter :counter :as ins} (render-ln inspector header1 header2)
obj obj
rows rows
idx idx-starts-from]
(if obj
(recur (-> ins
(update-in [:index] conj (first obj))
(update-in [:counter] inc)
(update-in [:rendered] concat (list (list :value (first rows) counter)))
(render-ln))
(next obj)
(next rows)
(inc idx))
ins)))
(loop [ins inspector, obj (seq obj), idx idx-starts-from]
(if obj
(recur (-> ins
(render-indent (str idx) ". ")
(render-value (first obj))
(render-ln))
(next obj) (inc idx))
ins)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment