-
-
Save razum2um/b691ad0d760795efaeb886e6caf05122 to your computer and use it in GitHub Desktop.
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
(defn postwalk-with-side-effect [x] | |
(let [state (atom []) | |
side-effect (fn [x] (if (:data x) (swap! state conj (:data x))))] | |
(clojure.walk/postwalk (fn [x] (side-effect x) x) x) | |
@state)) | |
(defn test [] | |
(= [1 2 3] | |
(postwalk-with-side-effect | |
{:data 3 :children [{:children {:children []}} | |
{:children [{:children [] :data 1}]} | |
{:children [] :data 2}]}) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this avoids mutating, doesn't have to build a collection that nobody uses, and for those reasons is likely more performant