Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns adhoc.core
(:require clojure.walk))
(defn prewalk-splice
[smap form]
(if-let [seq-reshaper (cond (seq? form) identity
(list? form) (partial apply list) ;; necessary?
;; map entries look like vectors
(instance? java.util.Map$Entry form) nil
(vector? form) vec
(set? form) set)]
;; we know how to splice into this form
(mapcat (fn [sub] (if (contains? smap sub)
(smap sub)
[(prewalk-splice smap sub)]))
;; otherwise let walk descend into it
(clojure.walk/walk (partial prewalk-splice smap) identity form)))
(prewalk-splice '{a [1 2 3] b [4 5 6]} '((. a ..) {#{:a b :C} [- b +]}))
#_((. 1 2 3 ..) {#{:C 4 5 6 :a} [- 4 5 6 +]}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.