Created
January 18, 2023 17:14
-
-
Save tatut/a0f4a88f3a86a030802b3ab2893e3b06 to your computer and use it in GitHub Desktop.
hack cider orchard.inspect/render-indexed-values to render a table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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