Skip to content

Instantly share code, notes, and snippets.

@brehaut
Created November 29, 2011 01:24
Show Gist options
  • Save brehaut/1402914 to your computer and use it in GitHub Desktop.
Save brehaut/1402914 to your computer and use it in GitHub Desktop.
apropos that returns a seq of symbols that include their namespace
;; 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