Skip to content

Instantly share code, notes, and snippets.

@verma
Last active September 6, 2019 06:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save verma/96ca5070d8556ccb5fe2 to your computer and use it in GitHub Desktop.
Save verma/96ca5070d8556ccb5fe2 to your computer and use it in GitHub Desktop.
pre-walk vs. post-walk
:profile_data
:ber
:value
11
[:value 11]
{:value 11}
[:ber 11]
:event_type
:value
foo
[:value foo]
{:value foo}
[:event_type foo]
{:ber 11, :event_type foo}
[:profile_data {:ber 11, :event_type foo}]
:conservatories
:area
:value
10
[:value 10]
{:value 10}
[:area 10]
:height
:value
11
[:value 11]
{:value 11}
[:height 11]
{:area 10, :height 11}
:area
:value
2
[:value 2]
{:value 2}
[:area 2]
:height
:value
1
[:value 1]
{:value 1}
[:height 1]
{:area 2, :height 1}
[{:area 10, :height 11} {:area 2, :height 1}]
[:conservatories [{:area 10, :height 11} {:area 2, :height 1}]]
:timestamp
:value
1
[:value 1]
{:value 1}
[:timestamp 1]
{:profile_data {:ber 11, :event_type foo}, :conservatories [{:area 10, :height 11} {:area 2, :height 1}], :timestamp 1}
{:profile_data {:ber 11, :event_type "foo"}, :conservatories [{:area 10, :height 11} {:area 2, :height 1}], :timestamp 1}
(def input {:profile_data {:ber {:value 11}, :event_type {:value "foo"}}, :conservatories [{:area {:value 10}, :height {:value 11}} {:area {:value 2}, :height {:value 1}}], :timestamp {:value 1}})
(def input {:profile_data {:ber {:value 11}, :event_type {:value "foo"}}, :conservatories [{:area {:value 10}, :height {:value 11}} {:area {:value 2}, :height {:value 1}}], :timestamp {:value 1} :other-stuff {:value nil}})
(clojure.walk/prewalk #(do
(println %)
(if (and (map? %)
(contains? % :value))
(:value %) %)) input)
(clojure.walk/postwalk #(do
(println %)
(if (and (map? %)
(contains? % :value))
(:value %) %)) input)
{:profile_data {:ber {:value 11}, :event_type {:value foo}}, :conservatories [{:area {:value 10}, :height {:value 11}} {:area
{:value 2}, :height {:value 1}}], :timestamp {:value 1}}
[:profile_data {:ber {:value 11}, :event_type {:value foo}}]
:profile_data
{:ber {:value 11}, :event_type {:value foo}}
[:ber {:value 11}]
:ber
{:value 11}
[:event_type {:value foo}]
:event_type
{:value foo}
[:conservatories [{:area {:value 10}, :height {:value 11}} {:area {:value 2}, :height {:value 1}}]]
:conservatories
[{:area {:value 10}, :height {:value 11}} {:area {:value 2}, :height {:value 1}}]
{:area {:value 10}, :height {:value 11}}
[:area {:value 10}]
:area
{:value 10}
[:height {:value 11}]
:height
{:value 11}
{:area {:value 2}, :height {:value 1}}
[:area {:value 2}]
:area
{:value 2}
[:height {:value 1}]
:height
{:value 1}
[:timestamp {:value 1}]
:timestamp
{:value 1}
{:profile_data {:ber 11, :event_type "foo"}, :conservatories [{:area 10, :height 11} {:area 2, :height 1}], :timestamp 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment