This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-10
Channels
- # beginners (35)
- # cider (165)
- # cljsrn (18)
- # clojars (1)
- # clojure (141)
- # clojure-greece (2)
- # clojure-italy (11)
- # clojure-nl (1)
- # clojure-spec (21)
- # clojure-uk (89)
- # clojurescript (56)
- # community-development (3)
- # cursive (3)
- # data-science (55)
- # datomic (13)
- # emacs (12)
- # fulcro (31)
- # graphql (6)
- # jobs-discuss (35)
- # lein-figwheel (10)
- # mount (2)
- # off-topic (3)
- # onyx (22)
- # parinfer (4)
- # portkey (7)
- # re-frame (29)
- # ring-swagger (4)
- # shadow-cljs (37)
- # specter (9)
- # sql (30)
- # tools-deps (15)
- # vim (2)
- # yada (17)
I'm having trouble figuring out how to navigate to an entry that could have a variable number of steps. An individual navigate/transform is easy enough and looks something like this:
(sp/transform [(node-named "2002") :children (node-named "01") :expanded] invert test-tree)
However I need to be able to provide a path that could have from 1 to 4 entries. In the above example it would be ["2002" "01"]
. What would be the best way to approach this?
I tried building the navigator with for
in a let
statement like this:(defn toggle [tree path]
(let [nav (conj
(vec
(interpose :children (for [p path] (conj (seq [p]) 'node-named ))))
:expanded)]
(sp/transform nav invert tree)))
But although this gives me a value for nav
that looks exactly right, running it throws Not a navigator
errorswhere node-named
invert
and test-tree
are:
(defn node-named [n]
(sp/walker #(= (:name %) n)))
(defn invert [b]
(if b false true))
(def test-tree
{:name "root"
:focus ["root"]
:expanded true
:children [{:name "2000"
:expanded true
:children [{:name "01"
:expanded true
:children [{:name "project-1"}
{:name "project-2"}]}
{:name "02"
:expanded true
:children [{:name "project-5"}
{:name "project-6"}]}]}
{:name "2002"
:expanded false
:children [{:name "01"
:expanded false
:children []}]}]})
try something like this:
(defn navigator [strs]
(path (mapcat (fn [s] [:children ALL #(= (:name %) s)]) strs)))
@U3L6TFEJF That looks promising, thanks. I'm getting the right node back now. Just got to massage it a bit to toggle :expanded. Which I will do with not
😳
remember that you can compose paths with a simple vector:
(transform [(navigator ["2000" "01"]) :expanded] not test-tree)
yup, got it working now. Still waiting for the ah-ha moment with specter, but it is doing some useful things even though often I'm not entirely sure why....