Skip to content

Commit d6dc4fc

Browse files
committed
Apply f based on pred in map-zip
1 parent ed543fa commit d6dc4fc

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/zipup/core.cljc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
last))
7272

7373
(defn map-zip
74-
"Applies f to every leaf node in the tree rooted at loc"
75-
[f loc]
74+
"Applies f to every node in the tree rooted at loc for which (pred loc) returns true"
75+
[f pred loc]
7676
(if (zip/end? loc)
7777
(root-loc loc)
78-
(recur f (zip/next (cond-> loc (leaf? loc) (zip/edit f))))))
78+
(recur f pred (zip/next (cond-> loc (pred loc) (zip/edit f))))))

test/zipup/core_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
(deftest map-zip-test
4747
(is (= [2 :a 3 [4]]
4848
(->> (z/vector-zip [1 :a 2 [3]])
49-
(zu/map-zip #(cond-> % (number? %) inc))
49+
(zu/map-zip inc (comp number? z/node))
5050
z/node)))
5151
(is (= ["1" ":a" "2" ["3"]]
5252
(->> (z/vector-zip [1 :a 2 [3]])
53-
(zu/map-zip str)
53+
(zu/map-zip str zu/leaf?)
5454
z/node))))

0 commit comments

Comments
 (0)