{:deps {gist-uwo/pformat {:git/url "https://gist.github.com/uwo/d702e3ceabd783ea7787afecdb0d470c"
:sha "9fe4cc9714865ac49adca56e73467ea8252bd4a5"}}}
Last active
July 4, 2018 22:20
-
-
Save uwo/c5ca5aa57e156364dd687cb0538836c6 to your computer and use it in GitHub Desktop.
pformat & pspit
This file contains 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
.nrepl-port | |
.cpcache |
This file contains 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
{:paths ["."] | |
:deps | |
{org.clojure/clojure {:mvn/version "1.9.0"}}} |
This file contains 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
(ns pformat | |
(:require [clojure.spec.alpha :as s])) | |
(def defaults | |
{:print-right-margin 72 | |
:print-namespace-maps false | |
:pprint-dispatch clojure.pprint/simple-dispatch}) | |
(defn pformat | |
([data] (pformat data defaults)) | |
([data opts] | |
(let [{:keys [print-right-margin | |
pprint-dispatch | |
print-namespace-maps]} | |
(merge defaults opts)] | |
(clojure.pprint/with-pprint-dispatch pprint-dispatch | |
(with-out-str | |
(binding [clojure.pprint/*print-right-margin* print-right-margin | |
*print-namespace-maps* print-namespace-maps] | |
(clojure.pprint/pprint data))))))) | |
(defn pspit | |
([filename data] (spit filename (pformat data))) | |
([filename data opts] (spit filename (pformat data opts)))) | |
(s/def ::opts | |
(s/keys :opt-un [::print-right-margin | |
::print-namespace-maps | |
::pprint-dispatch])) | |
(s/fdef pformat | |
:args (s/cat :data any? | |
:opts (s/? ::opts))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment