Fork me on GitHub
#specter
<
2020-04-13
>
nonrecursive03:04:32

hey hey 🙂 How would I return a map where all paths that don’t terminate in an integer have been pruned? Given:

{:a {:b {:c 10
         :d ""}}
 :f 5
 :k [10]
 :m ""
 :x {:y {:z ""}}}
I want:
{:a {:b {:c 10}}
 :f 5
 :k [10]}

nathanmarz22:04:24

@nonrecursive you can do that with a custom walker and compact :

(def COMPACTING-WALKER
  (recursive-path [] p
    (cond-path map? [(compact MAP-VALS) p]
               coll? [(compact ALL) p]
               STAY STAY
               )))

(setval [COMPACTING-WALKER (complement number?)]
  NONE
  data
  )

💯 4