This version of lprocess works fine:
(defn lprocess
"Process all locations that match the predicate function with the supplied
mapping function. Locations that do not match are unchanged."
[pred func ent]
(loop [l (zip/vector-zip ent)]
(if (zip/end? l)
(zip/root l)
(if (pred l)
(recur (zip/next (func l)))
(recur (zip/next l))))))
Since I'm not doing anything with the lazy sequence anyway I think I'll switch
to this version. Still unsure why the other one didn't work for the last
element.
On Sunday, April 12, 2015 at 11:57:14 AM UTC+8, Elliot Bulmer wrote:
> Hi guys,
>
> I'm writing a simple entity-component system for a game. An entity in this
> case is a vector of components and a component is just a map. Entities can be
> nested in a tree structure. I am using clojure.zip to traverse this tree and
> operate on the entities/components.
>
> https://gist.github.com/sonelliot/e44662320b29d1c7b4b4#file-last-node-zipper-cljs
>
> The 'lprocess' function processes an entity by mapping a function over all
> locations for which the predicate is true. Locations that don't match are
> unchanged.
>
> Once the tree is processed I return the root of the last item. But this
> doesn't seem to work how I thought it would.
>
> I've tried something like (zip/next) (zip/root) but this doesn't work either.
> What am I misunderstanding about this?
>
> Any advice would be appreciated. Many thanks :)
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.