This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-25
Channels
- # aleph (12)
- # announcements (2)
- # beginners (40)
- # calva (8)
- # cider (26)
- # cljs-dev (71)
- # cljsrn (2)
- # clojure (122)
- # clojure-dev (9)
- # clojure-europe (2)
- # clojure-nl (2)
- # clojure-spec (42)
- # clojure-uk (20)
- # clojurescript (86)
- # cursive (15)
- # data-science (1)
- # datomic (42)
- # duct (4)
- # emacs (33)
- # events (1)
- # figwheel-main (2)
- # fulcro (33)
- # jobs (2)
- # jobs-discuss (46)
- # kaocha (13)
- # leiningen (9)
- # off-topic (62)
- # pathom (75)
- # quil (2)
- # re-frame (6)
- # reagent (13)
- # reitit (3)
- # shadow-cljs (52)
- # spacemacs (3)
- # specter (17)
- # sql (6)
- # tools-deps (2)
- # vim (3)
- # yada (28)
I have a set of nested records. In my structure, I want to STAY on the i. the value nodes with :bar keys, that are ii. not seqable? and iii. not of type myns.Foo. But I can’t seem to get the recursive navigator correctly. Any ideas here?
(def a #myns.Foo{:bar #myns.Foo{:bar (#myns.Foo{:bar :a :x 1 :y 2} :b :c :d)}})
(def b (recursive-path
[] p
(cond-path
seqable? [ALL p]
[:matcher (comp clojure.core/not parser-combinator?)] (continue-then-stay ALL p)
[:matcher (comp clojure.core/not seqable?)] [ALL p])))
(select b a)
@twashing it would be more clear if you showed desired input and output
Hey @nathanmarz, absolutely. So I’m trying to find the recursive-path
that gives me the output in *B, given the input from A*.
;; A input structure
(defrecord Foo [bar])
(def a #user.Foo{:bar #user.Foo{:bar '(#user.Foo{:bar :a :x 1 :y 2} :b :c :d)}})
;; B output
:a ;; (the i. the value nodes with :bar keys, that are ii. not seqable? and iii. not of type myns.Foo)
@twashing is this what you're looking for?
(def MY-WALKER
(recursive-path [] p
(cond-path
#(instance? Foo %) [:bar p]
seqable? [ALL #(instance? Foo %) p]
STAY STAY
)))
@nathanmarz Hmm, if I put this into my repl, I get an empty result set.
(use 'com.rpl.specter)
(defrecord Foo [bar])
(def a #user.Foo{:bar #user.Foo{:bar '(#user.Foo{:bar :a :x 1 :y 2} :b :c :d)}})
(def MY-WALKER
(recursive-path [] p
(cond-path
#(instance? Foo %) [:bar p]
seqable? [ALL #(instance? Foo %) p]
STAY STAY)))
(select MY-WALKER a)
;; [] - empty result set returned
@twashing probably because you meant to do (def a #user.Foo{:bar #user.Foo{:bar (#user.Foo{:bar :a :x 1 :y 2} :b :c :d)}})
?
Cheers mate. I think I have a better understanding of the semantics of if-path
and cond-path
.
Although STAY STAY
(to capture the leaves) is still a bit foggy.. used as both a predicate and navigator.
@twashing An if-path
/`cond-path` condition is "true" if it navigates to at least one value
so STAY
is the navigation equivalent of true