Created
November 29, 2011 01:24
-
-
Save brehaut/1402914 to your computer and use it in GitHub Desktop.
apropos that returns a seq of symbols that include their namespace
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
| ;; hacked out of clojure.repl/apropos and prepending namespaces | |
| (defn apropos-ns | |
| "Given a regular expression or stringable thing, return a seq of | |
| all definitions in all currently-loaded namespaces that match the | |
| str-or-pattern." | |
| [str-or-pattern] | |
| (let [matches? (if (instance? java.util.regex.Pattern str-or-pattern) | |
| #(re-find str-or-pattern (str %)) | |
| #(.contains (str %) (str str-or-pattern)))] | |
| (mapcat (fn [ns] | |
| (let [ns-name (.name names)] | |
| (->> (keys (ns-publics ns)) | |
| (filter matches?) | |
| (map #(symbol ns-name (name %)))))) | |
| (all-ns)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment