Skip to content

Instantly share code, notes, and snippets.

@dvliman
Created August 27, 2024 16:06
Show Gist options
  • Select an option

  • Save dvliman/9ae80ebbba797fde22e0f1915ce9f93c to your computer and use it in GitHub Desktop.

Select an option

Save dvliman/9ae80ebbba797fde22e0f1915ce9f93c to your computer and use it in GitHub Desktop.

Revisions

  1. dvliman created this gist Aug 27, 2024.
    31 changes: 31 additions & 0 deletions user.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    (def log-store (atom {}))

    (defn debug [tag val]
    (swap! log-store update-in [tag] #(conj (or % []) val))
    val)

    (defn logs
    [tag & functions]
    (let [tag (if (number? tag)
    (nth (keys @log-store) tag)
    tag)]
    (loop [values (@log-store tag)
    functions functions]
    (if (seq functions)
    (recur ((first functions) values)
    (rest functions))
    values))))

    (defn same-values? [x]
    (if (= 1 (count (set x)))
    :same-values
    :different-values))

    (defn tags []
    (->> @log-store
    (reduce-kv #(assoc %1 [(count %3) (same-values? %3) %2] (last %3)) {})
    (map-indexed hash-map)
    (into [])))

    (defn debug-data-reader [form]
    `(debug (quote ~form) ~form))