Hi Moi,
Thanks a lot for your patience and help.
I tried this so far:
(defn edit-parents [editable? edit loc]
(loop [loc loc]
(if (z/end? loc)
(z/root loc)
(if (editable? (z/node loc))
(recur (-> loc z/up (z/edit edit) z/up z/next))
(recur (z/next loc))))))
(defn predicate [x]
(and
(vector? x)
(some #(= 10 (get-in % ["a" "b"])) x)))
(defn operation [x] (update x "children" reverse))
(edit-parents predicate operation (z/seq-zip {"children" z}))
But I'm still getting the same data. What I'm doing wrong?
Thanks a lot.
On Monday, August 24, 2015 at 4:08:17 PM UTC+2, Moe Aboulkheir wrote:
>
> Went off half-cocked there. The remainder:
>
> (edit-parents
> #(= 10 (get-in % ["a" "b"]))
> #(update % "children" reverse),
> data-zipper)
>
> Would have the effect of reversing the order of the children in each node
> which possesses a child having a "b" attribute set to 10. You could
> probably express this much better with a library which allows locations in
> data structures to be described in an XPath-like way (and your data
> actually looks a lot like it is the result of parsing markup - see
> clojure.data.xml and xml-zip if so) -- or there's probably some better
> zipper approach that somebody who's really into zippers could come up with.
>
> If you don't want to depend on an external library, and you lose your
> enthusiasm for zippers, you could write a function which goes over the
> structure and returns pairs of [[path] attributes], where path is a
> sequence of keys/indices suitable for passing to update-in/assoc-in etc.,
> and attributes is the value of the "a" key at each level.
>
> In general, if there aren't multiple keys similar to "a" in each map (i.e.
> it's always some value pointing to some map, and the value is not always
> "a"), this kind of layout may be easier (e.g. to destructure)
>
> {:tag "a" :attrs {:b 10} :children [...]}}
>
> Take care,
> Moe
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.