Back

print-table (clj)

(source)

function

(print-table ks rows) (print-table rows)
Prints a collection of maps in a textual table. Prints table headings ks, and then a line of output for each row, corresponding to the keys in ks. If ks are not specified, use the keys of the first item in rows.

Examples

jpmonettas/clindex
(ns workbench
  (:require [clojure.tools.namespace.find :as ns-find]
            [clojure.tools.namespace.dir :as ns-dir]
            [clojure.tools.namespace.track :as ns-track]
            [clojure.tools.namespace.parse :as ns-parse]
            [clojure.tools.namespace.dependency :as dep]
            [clojure.java.io :as io]
            [datascript.core :as d]
            [clindex.api :as capi]
            [clindex.scanner :as scanner]
            [clojure.pprint :as pprint]
            [clindex.forms-facts.core :as forms-facts]
            [clindex.utils :as utils]))

  ;; now you can query the dbs
  ;; lets query all the vars that start with "eval"
  (->> (d/q '[:find ?vname ?nname ?pname ?vline ?fname
                  :in $ ?text
                  :where
                  [?fid :file/name ?fname]
                  [?pid :project/name ?pname]
                  [?nid :namespace/file ?fid]
                  [?pid :project/namespaces ?nid]
                  [?nid :namespace/name ?nname]
                  [?nid :namespace/vars ?vid]
                  [?vid :var/name ?vname]
                  [?vid :var/line ?vline]
                  [(str/starts-with? ?vname ?text)]]
                db
                "eval")
       (map #(zipmap [:name :ns :project :line :file] %))
       (pprint/print-table))

  ;; who uses clojure.core/juxt ?
  (let [juxt-vid (d/q '[:find ?vid .
                    :in $ ?nsn ?vn
                    :where
                    [?nsid :namespace/name ?nsn]
                    [?nsid :namespace/vars ?vid]
                    [?vid :var/name ?vn]]
                  db
                  'clojure.core
                  'juxt)]
    (-> (d/pull db [{:var/refs [{:var-ref/namespace [:namespace/name]} :var-ref/line]}] juxt-vid)
        :var/refs
        (clojure.pprint/print-table)))
clj-holmes/clj-holmes
(ns clj-holmes.output.main
  (:require [clj-holmes.output.json :as output.json]
            [clj-holmes.output.sarif :as output.sarif]
            [clj-holmes.output.stdout :as output.stdout]
            [clojure.data.json :as json]
            [clojure.pprint :as pprint])
  (:import (java.io OutputStreamWriter)))

(defmethod output :stdout [results _]
  (let [stdout-result (output.stdout/output results)]
    (binding [*out* (OutputStreamWriter. System/out)]
      (pprint/print-table stdout-result)
      stdout-result)))
PacktWorkshops/The-Clojure-Workshop
(require 'clojure.pprint)

(clojure.pprint/print-table [{:text "Clojure"}{:text "is"}{:text "fun"}])

(pprint/print-table [{:text "Clojure"}{:text "is"}{:text "fun"}])

(print-table [{:text "Clojure"}{:text "is"}{:text "fun"}])
cognitect-labs/day-of-datomic-cloud
(require '[datomic.client.api :as d]
         '[clojure.pprint :as pp])

(->> (d/q '[:find ?e ?a ?v ?tx ?op
            :in $
            :where [?e :crud/name "Hello world"]
            [?e ?a ?v ?tx ?op]]
          history)
     (map #(zipmap [:e :a :v :tx :op] %))
     (sort-by :tx)
     (pp/print-table [:e :a :v :tx :op]))
Datomic/client-examples
(require '[clojure.pprint :as pp])

(->> (client/q conn
       {:query '[:find ?e ?a ?v ?tx ?op
                 :in $
                 :where [?e :crud/name "Hello world"]
                 [?e ?a ?v ?tx ?op]]
        :args [history]})
  <!!
  (map #(zipmap [:e :a :v :tx :op] %))
  (sort-by :tx)
  (pp/print-table [:e :a :v :tx :op]))