Created
April 12, 2015 03:51
-
-
Save egbulmer/e44662320b29d1c7b4b4 to your computer and use it in GitHub Desktop.
Last location in zip function is not being updated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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] | |
| (->> | |
| (iterate (fn [l] | |
| (if (pred l) | |
| (zip/next (func l)) | |
| (zip/next l))) (zip/vector-zip ent)) | |
| (take-while (complement zip/end?)) | |
| (last) (zip/root))) | |
| (defn component-process [pred func ent] | |
| (lprocess #(and (not (zip/branch? %)) (pred (zip/node %))) | |
| #(zip/edit % func) ent)) | |
| (def ent | |
| [{:name :transform :position [0 0] :rotation 0 :scale [1 1]} | |
| {:name :sprite, :file "foo", :ext ".png"} | |
| {:name :sprite, :file "foo", :ext ".png"} | |
| {:name :sprite, :file "foo", :ext ".png"}]) | |
| (component-process #(= :sprite (:name %)) #(assoc % :foo :bar) ent) | |
| ;; [{:name :transform :position [0 0] :rotation 0 :scale [1 1]} | |
| ;; {:name :sprite, :file "foo", :ext ".png", :foo :bar} | |
| ;; {:name :sprite, :file "foo", :ext ".png", :foo :bar} | |
| ;; {:name :sprite, :file "foo", :ext ".png"}] | |
| ;; Last element isn't updated! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment