Skip to content

Instantly share code, notes, and snippets.

@spieden
Created September 18, 2018 20:22
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 spieden/92a41ac80361c2cdaa68306efbb1cfba to your computer and use it in GitHub Desktop.
Save spieden/92a41ac80361c2cdaa68306efbb1cfba to your computer and use it in GitHub Desktop.
(ns hiccup-paths
(:require [com.rpl.specter :as spr]))
(def tags-recursive
(spr/recursive-path [tags] p
(spr/cond-path
#(and (vector? %)
(tags (first %)))
spr/STAY
#(and (coll? %)
(not (map? %)))
[spr/ALL p])))
(defn tag [tag]
#(and (vector? %)
(= (first %) tag)))
(defn child-tag [t]
(spr/comp-paths spr/ALL
(tag t)))
(spr/defnav
NONE->val
[v]
(select* [this structure next-fn]
(next-fn (if (= structure spr/NONE) v structure)))
(transform* [this structure next-fn]
(next-fn (if (= structure spr/NONE) v structure))))
(def ATTRS
(spr/if-path [1 map?]
1
[(spr/before-index 1)
(NONE->val {})]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment