This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-08
Channels
- # aws (9)
- # beginners (69)
- # boot (14)
- # cider (26)
- # cljs-dev (56)
- # cljsrn (9)
- # clojars (4)
- # clojure (229)
- # clojure-brasil (1)
- # clojure-france (11)
- # clojure-greece (2)
- # clojure-italy (4)
- # clojure-mke (6)
- # clojure-serbia (6)
- # clojure-spec (83)
- # clojure-uk (38)
- # clojurescript (171)
- # core-async (3)
- # cursive (11)
- # data-science (11)
- # datomic (27)
- # emacs (113)
- # funcool (6)
- # hoplon (4)
- # jobs (1)
- # luminus (13)
- # lumo (44)
- # off-topic (148)
- # onyx (5)
- # overtone (1)
- # pedestal (4)
- # powderkeg (1)
- # proton (2)
- # re-frame (150)
- # reagent (16)
- # ring-swagger (43)
- # spacemacs (4)
- # specter (36)
- # vim (4)
- # yada (10)
@nathanmarz I looked at traverse and not sure it does what I need. I have a tree structure of deeply nested records which I would like to walk/transform. Some of these are condition records that should stop navigation of the subtree underneath if the condition (a vector of predicate functions) does not return true. Does that make sense? I have tried to illustrate the structure below. Navigation should not get to the action records of type :three and :three-and-a-half but allow me to select/transform the other records based on some criteria.
@mac what do you run the predicate function on?
what is #(= % 3)
supposed to receive as input?
@nathanmarz I will pass it the children it is guarding and probably an environment of some sort (a map most likely).
from your prior description it sounded like you needed to get some functions out of a nested structure and run them
to do this, once you get to a condition, just use a function to filter it
(defn cond-filter [cond]
;; return true if every condition function returns true)
then your path would contain [... cond-filter :actions ALL ...]
@nathanmarz Sorry for the confusion. I only need to run the functions to determine if the subtree they are guarding should be walked or skipped.
@mac does making a function that runs the condition functions solve your problem?
@nathanmarz I don't think so. Only if I the result could control if the children of the Condition record are walked or not - the problem is I don't know how to do that. Been looking at zippers too, but last time I dealt with them it was painful 🙂
it does control that
that's exactly what it does
your path should navigate to condition, then run a filter function there to do all the logic of testing the predicates against the guarded children
if that returns true, then it can continue walking the actions
if it returns false, then the actions will not be walked
@nathanmarz I might be missing something here, but I don't have a path at all, only a walker.
you mean you're using the walker
navigator?
wrap it in a recursive-path
what are you walking to?
Action
or Condition
?
actually, is your goal to just retrieve all actions that are properly guarded?
(def SATISFACTORY-ACTION-NODES
(recursive-path [] p
(if-path #(instance? Condition %)
[cond-filter :children ALL p]
(continue-then-stay
:children
ALL
p
))))
you want something like that
I don't think you want to use walker
it's always better to encode the precise structure of your data rather than brute force it with walker
an alternative way to solve this is with protocol paths (if you're using clojure)
protocol path solution would be extensible to other types of nodes beyond Action and Condition
there's examples of those on the README
Yeah, looked at those but it wasn't clear to me how to achieve my goal. Will look at them again.
(defprotocolpath SatisfactoryActionNodes)
(extend-protocolpath SatisfactoryActionNodes
Action (continue-then-stay :children ALL SatisfactoryActionNodes)
Condition [cond-filter :children ALL SatisfactoryActionNodes])
@nathanmarz That it is very elegant.