This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-12
Channels
- # bangalore-clj (1)
- # beginners (28)
- # boot (33)
- # chestnut (3)
- # cider (35)
- # cljs-dev (64)
- # cljsrn (16)
- # clojure (95)
- # clojure-android (6)
- # clojure-austin (1)
- # clojure-italy (5)
- # clojure-korea (1)
- # clojure-russia (55)
- # clojure-sg (1)
- # clojure-spec (25)
- # clojure-uk (57)
- # clojurescript (120)
- # code-reviews (7)
- # community-development (2)
- # core-async (3)
- # cursive (6)
- # data-science (3)
- # datascript (10)
- # datomic (12)
- # devcards (1)
- # emacs (9)
- # gsoc (7)
- # hoplon (18)
- # lumo (2)
- # off-topic (10)
- # om (24)
- # onyx (17)
- # pedestal (46)
- # powderkeg (1)
- # protorepl (7)
- # re-frame (31)
- # ring-swagger (34)
- # spacemacs (10)
- # specter (9)
- # sql (39)
- # unrepl (9)
- # untangled (3)
- # utah-clojurians (1)
Hey everyone! I've got a nested map (It's a deserialization of a flat file JSON "database" for a budgeting app I'm extending) that looks similar to this (stripped down somewhat):
{:categories [{:name "Monthly bills"
:subcategories [{:name "Electric"}
{:name "Cable" :inactive true}
{:name "Mortgage"}
{:name "Natural Gas"}]}
{:name "Food"
:subcategories [{:name "Eating Out"}
{:name "Groceries"}]}
{:name "Stuff"
:inactive true
:subcategories [{:name "Things" :inactive true}
{:name "Whatever"}]}]
:accounts [{:name "Checking"
:balance 100}
{:name "Old account"
:balance 0
:inactive true}
{:name "Savings"
:balance 500}]}
I'm fairly new to specter, and am still learning about what's possible. How would I recursively remove all maps at all levels that have an :inactive true
flag? The result I would get from the above would be:
{:categories [{:name "Monthly bills"
:subcategories [{:name "Electric"}
{:name "Mortgage"}
{:name "Natural Gas"}]}
{:name "Food"
:subcategories [{:name "Eating Out"}
{:name "Groceries"}]}]
:accounts [{:name "Checking"
:balance 100}
{:name "Savings"
:balance 500}]}
@ksmithbaylor it would be something like:
(def NODES
(recursive-path [] p
(continue-then-stay
(must :subcategories) ALL p
)))
(setval [(multi-path :categories :accounts)
ALL
NODES
(pred :inactive)]
NONE
data)
This is doing almost what I want: (setval [(walker #(and (map? %) (:inactive %)))] nil data)
but now I need to recursively remove the nil
s
I'd like to keep it generic so I don't need to know/care what keys are in each level
it's generally better to be more precise about the structure of your data
walker
doesn't perform well and has some pitfalls
you can just replace nil
with NONE
there to get the maps removed
actually nevermind, walker
doesn't implement NONE
removal