Last active
August 29, 2015 14:14
-
-
Save fbellomi/9832211d53bd0a1dd49b to your computer and use it in GitHub Desktop.
Pretty printer for core.typed annotations
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 pp-type [f] | |
(if (and (sequential? f) (<= 3 (count f)) (symbol? (first f)) (= (name (first f)) "All")) | |
(str "(All " (pr-str (second f)) "\n " (str/join "\n " (str/split (pp-type (nth f 2)) #"\n" )) ")") | |
(if (and (sequential? f) (<= 3 (count f)) (symbol? (first f)) (= (name (first f)) "IFn")) | |
(str "(IFn " (str/join "\n " (map pr-str (rest f))) ")") | |
(pr-str f)))) | |
(defn pretty-print-type [f] | |
(-> (pp-type f) | |
(str/replace #"(clojure\.core\.typed/)|(clojure\.lang\.)|(java\.lang\.)" "") | |
(str/replace "(U " "(\u222a ") | |
(str/replace "(I " "(\u2229 ") | |
(str/replace "(All " "(\u2200 ") | |
(str/replace "(IFn " "(\u03bb ") | |
(str/replace " -> " " \u2192 ") | |
(str/replace "[-> " "[\u2192 ") | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's the one currently used by http://crossclj.info
Some cases are not well covered.