title: how can I recursively flatten arbitrarily nested vectors and maps in Clojure?
body: <p>I am trying to use recursion to walk a tree of arbitrarily nested vectors and maps in Clojure, and return a vector of just the keywords, including the tops. </p>
  
  <p>So the below sample data should return: </p>
  
  <p><code>[:top :top :top :top :top :top :top :top :bottom :bottom :bottom :bottom :bottom :bottom :bottom :bottom :bottom :bottom :bottom :bottom]</code>, </p>
  
  <p>but in no particular order. </p>
  
  <p>Could somebody please help me to do this correctly? Below is what I have so far.</p>
  
  <pre><code>(def sample [{:top {:top {:top [:bottom {:top {:top [:bottom :bottom :bottom]}} :bottom :bottom :bottom]}}}, 
                          {:top {:top [:bottom :bottom :bottom]}}, 
                          {:top [:bottom :bottom]}])
  
  (defn make-flat [graph]
    (loop [graph graph]
      (if (every? keyword? graph) graph
        (recur (into graph (flatten (seq (first (filter #(not (keyword? %)) graph)))))))))
  
  (make-flat sample)
  </code></pre>