Skip to content

Instantly share code, notes, and snippets.

@mecdemort
Created March 31, 2011 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mecdemort/895803 to your computer and use it in GitHub Desktop.
Save mecdemort/895803 to your computer and use it in GitHub Desktop.
mec.walk
(ns mec.walk)
(defn f-walk [inner outer form]
(outer
(if (coll? form)
(into (empty form) (map inner form))
form)))
(defn f-postwalk
"Depth first post-order traversal of form, apply successive fs at each level.
(f1 (map f2 [..]))"
[[f & fs] form]
(if (seq fs)
(f-walk (partial f-postwalk fs) f form)
(f form)))
(defn f-postwalk
"Depth first post-order traversal of form, apply successive fs at each level.
(f1 (map f2 [..]))"
[[f & fs] form]
(f
(if (and (seq fs) (coll? form))
(into (empty form) (map (partial generic-walk fs) form))
form)))
(defn f-prewalk
"Pre-order traversal of form, apply successive fs at each level.
(.. (map f2 (f1 [..])))"
[[f & fs] form]
(if (and (seq fs) (coll? form))
(into (empty form) (map (partial generic-walk fs) (f form)))
(f form)))
(defn f-prewalk
"Pre-order traversal of form, apply successive fs at each level.
(.. (map f2 (f1 [..])))"
[[f & fs] form]
(if (seq fs)
(f-walk (partial f-prewalk fs) identity (f form))
(f form)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment