-
Notifications
You must be signed in to change notification settings - Fork 61
/
walk.cljc
22 lines (20 loc) · 873 Bytes
/
walk.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(ns aero.impl.walk)
(defn- walk
[inner outer form]
(let [x (cond
(list? form) (outer (apply list (map inner form)))
#?@(:cljs [(map-entry? form) (outer (MapEntry. (inner (key form)) (inner (val form)) nil))]
:clj [(instance? clojure.lang.IMapEntry form) (outer (vec (map inner form)))])
(seq? form) (outer (doall (map inner form)))
#?(:cljs (record? form)
:clj (instance? clojure.lang.IRecord form))
(outer (reduce (fn [r x] (conj r (inner x))) form form))
(coll? form) (outer (into (empty form) (map inner form)))
:else (outer form))]
(if #?(:cljs (implements? IWithMeta x)
:clj (instance? clojure.lang.IObj x))
(with-meta x (merge (meta form) (meta x)))
x)))
(defn postwalk
[f form]
(walk (partial postwalk f) f form))