(bottom-most? zip)
check if at bottom-most point of a branch
(-> (zip/from-cursor '[1 2 [3 4 |]]) (bottom-most?)) => true
check if at bottom-most point of a branch (-> (zip/from-cursor '[1 2 [3 4 |]]) (bottom-most?)) => true
(cursor zip)
returns the form with the cursor showing
(-> (vector-zip [1 [[2] 3]]) (find-next even?) (cursor)) => '([1 [[| 2] 3]])
returns the form with the cursor showing (-> (vector-zip [1 [[2] 3]]) (find-next even?) (cursor)) => '([1 [[| 2] 3]])
(cursor-str zip)
returns the string form of the cursor
(-> (vector-zip [1 [[2] 3]]) (find-next even?) (cursor-str)) => "[1 [[| 2] 3]]"
returns the string form of the cursor (-> (vector-zip [1 [[2] 3]]) (find-next even?) (cursor-str)) => "[1 [[| 2] 3]]"
(delete-left {:keys [left] :as zip})
(delete-left zip num)
delete element/s left of the current position
(-> (zip/from-cursor '[1 2 | 3]) (delete-left) (zip/cursor)) => '([1 | 3])
delete element/s left of the current position (-> (zip/from-cursor '[1 2 | 3]) (delete-left) (zip/cursor)) => '([1 | 3])
(delete-right {:keys [right] :as zip})
(delete-right zip num)
delete element/s right of the current position
(-> (zip/from-cursor '[1 2 | 3]) (delete-right) (zip/cursor)) => '([1 2 |])
delete element/s right of the current position (-> (zip/from-cursor '[1 2 | 3]) (delete-right) (zip/cursor)) => '([1 2 |])
(down zip)
move cursor down
(-> (from-cursor '[1 [| [2] 3]]) (down) (cursor)) => '([1 [[| 2] 3]])
move cursor down (-> (from-cursor '[1 [| [2] 3]]) (down) (cursor)) => '([1 [[| 2] 3]])
(end zip)
move cursor to the end of the tree (->> (vector-zip [1 [2 [6 7] 3] [4 5]]) (end) (cursor)) => '([1 [2 [6 7] 3] [4 | 5]])
move cursor to the end of the tree (->> (vector-zip [1 [2 [6 7] 3] [4 5]]) (end) (cursor)) => '([1 [2 [6 7] 3] [4 | 5]])
(find-next zip pred)
move cursor through the tree in depth first order to the first matching element
(-> (vector-zip [1 [2 [6 7] 3] [4 5]]) (find-next #(= 7 %)) (cursor)) => '([1 [2 [6 | 7] 3] [4 5]])
move cursor through the tree in depth first order to the first matching element (-> (vector-zip [1 [2 [6 7] 3] [4 5]]) (find-next #(= 7 %)) (cursor)) => '([1 [2 [6 | 7] 3] [4 5]])
(find-prev zip pred)
move cursor through the tree in reverse order to the last matching element
(-> (from-cursor '[1 [2 [6 | 7] 3] [4 5]]) (find-prev even?) (cursor)) => '([1 [2 [| 6 7] 3] [4 5]])
move cursor through the tree in reverse order to the last matching element (-> (from-cursor '[1 [2 [6 | 7] 3] [4 5]]) (find-prev even?) (cursor)) => '([1 [2 [| 6 7] 3] [4 5]])
(from-cursor arr)
returns a zipper given a data structure with | as the cursor
(from-cursor '[1 2 3 | 4]) => (contains {:left '(3 2 1), :right '(4)})
returns a zipper given a data structure with | as the cursor (from-cursor '[1 2 3 | 4]) => (contains {:left '(3 2 1), :right '(4)})
(history zip)
accesses the zipper history
(-> (vector-zip [1 [2 3]]) (move-down) (move-right) (history)) => [[:down] [:right]]
accesses the zipper history (-> (vector-zip [1 [2 3]]) (move-down) (move-right) (history)) => [[:down] [:right]]
(insert-left zip element)
(insert-left zip element & more)
insert element/s left of the current position
(-> (zip/from-cursor '[1 2 [[| 3] 4]]) (insert-left 1 2 3) (zip/cursor)) => '([1 2 [[1 2 3 | 3] 4]])
insert element/s left of the current position (-> (zip/from-cursor '[1 2 [[| 3] 4]]) (insert-left 1 2 3) (zip/cursor)) => '([1 2 [[1 2 3 | 3] 4]])
(insert-right zip element)
(insert-right zip element & more)
insert element/s right of the current position
(-> (zip/from-cursor '[| 1 2 3]) (insert-right 1 2 3) (zip/cursor)) => '([| 3 2 1 1 2 3])
insert element/s right of the current position (-> (zip/from-cursor '[| 1 2 3]) (insert-right 1 2 3) (zip/cursor)) => '([| 3 2 1 1 2 3])
(left zip)
move cursor left
(-> (from-cursor [1 '| 2 3]) (left) (cursor)) => '([| 1 2 3])
move cursor left (-> (from-cursor [1 '| 2 3]) (left) (cursor)) => '([| 1 2 3])
(left-most? zip)
check if at left-most point of a branch
(-> (zip/from-cursor [1 2 ['| 3 4]]) (left-most?)) => true
check if at left-most point of a branch (-> (zip/from-cursor [1 2 ['| 3 4]]) (left-most?)) => true
(left-node zip)
element directly left of current position
(-> (zip/from-cursor '[1 2 3 | 4]) (left-node)) => 3
element directly left of current position (-> (zip/from-cursor '[1 2 3 | 4]) (left-node)) => 3
(left-nodes zip)
all elements left of current position
(-> (zip/from-cursor '[1 2 | 3 4]) (left-nodes)) => '(1 2)
all elements left of current position (-> (zip/from-cursor '[1 2 | 3 4]) (left-nodes)) => '(1 2)
(move-bottom-most zip)
move to bottom-most point of current branch
(-> (zip/from-cursor '[1 2 | [[3] 4]]) (move-bottom-most) (zip/cursor)) => '([1 2 [[| 3] 4]])
move to bottom-most point of current branch (-> (zip/from-cursor '[1 2 | [[3] 4]]) (move-bottom-most) (zip/cursor)) => '([1 2 [[| 3] 4]])
(move-down zip)
(move-down zip num)
move down from current position
(-> (zip/from-cursor '[1 2 | [3 4]]) (move-down) (zip/cursor)) => '([1 2 [| 3 4]])
move down from current position (-> (zip/from-cursor '[1 2 | [3 4]]) (move-down) (zip/cursor)) => '([1 2 [| 3 4]])
(move-down? zip)
check if can move down from current position
(-> (zip/from-cursor '[1 2 [3 4 |]]) (move-down?)) => false
(-> (zip/from-cursor '[1 2 | [3 4]]) (move-down?)) => true
check if can move down from current position (-> (zip/from-cursor '[1 2 [3 4 |]]) (move-down?)) => false (-> (zip/from-cursor '[1 2 | [3 4]]) (move-down?)) => true
(move-left {:keys [left right] :as zip})
(move-left zip num)
move left from current position
(-> (zip/from-cursor '[1 2 [3 4 |]]) (move-left) (zip/cursor)) => '([1 2 [3 | 4]])
move left from current position (-> (zip/from-cursor '[1 2 [3 4 |]]) (move-left) (zip/cursor)) => '([1 2 [3 | 4]])
(move-left-most zip)
move to left-most point of current branch
(-> (zip/from-cursor '[1 2 [3 4 |]]) (move-left-most) (zip/cursor)) => '([1 2 [| 3 4]])
move to left-most point of current branch (-> (zip/from-cursor '[1 2 [3 4 |]]) (move-left-most) (zip/cursor)) => '([1 2 [| 3 4]])
(move-left? zip)
check if can move left from current position
(-> (zip/from-cursor '[1 2 [3 | 4]]) (move-left?)) => true
(-> (zip/from-cursor '[1 2 [| 3 4]]) (move-left?)) => false
check if can move left from current position (-> (zip/from-cursor '[1 2 [3 | 4]]) (move-left?)) => true (-> (zip/from-cursor '[1 2 [| 3 4]]) (move-left?)) => false
(move-right {:keys [left right] :as zip})
(move-right zip num)
move right from current position
(-> (zip/from-cursor '[1 2 [| 3 4]]) (move-right) (zip/cursor)) => '([1 2 [3 | 4]])
move right from current position (-> (zip/from-cursor '[1 2 [| 3 4]]) (move-right) (zip/cursor)) => '([1 2 [3 | 4]])
(move-right-most zip)
move to right-most point of current branch
(-> (zip/from-cursor '[1 2 [| 3 4]]) (move-right-most) (zip/cursor)) => '([1 2 [3 4 |]])
move to right-most point of current branch (-> (zip/from-cursor '[1 2 [| 3 4]]) (move-right-most) (zip/cursor)) => '([1 2 [3 4 |]])
(move-right? zip)
check if can move right from current position
(-> (zip/from-cursor '[1 2 [3 | 4]]) (move-right?)) => true
(-> (zip/from-cursor '[1 2 [3 4 |]]) (move-right?)) => false
check if can move right from current position (-> (zip/from-cursor '[1 2 [3 | 4]]) (move-right?)) => true (-> (zip/from-cursor '[1 2 [3 4 |]]) (move-right?)) => false
(move-top-most zip)
move to top-most point of the tree
(-> (zip/from-cursor '[1 2 [| 3 4]]) (move-top-most) (zip/cursor)) => '(| [1 2 [3 4]])
move to top-most point of the tree (-> (zip/from-cursor '[1 2 [| 3 4]]) (move-top-most) (zip/cursor)) => '(| [1 2 [3 4]])
(move-up zip)
(move-up zip num)
move up from current position
(-> (zip/from-cursor '[1 2 [| 3 4]]) (move-up) (zip/cursor)) => '([1 2 | [3 4]])
move up from current position (-> (zip/from-cursor '[1 2 [| 3 4]]) (move-up) (zip/cursor)) => '([1 2 | [3 4]])
(move-up? zip)
check if can move up from current position
(-> (zip/from-cursor '[1 2 [3 4 |]]) (move-up?)) => true
check if can move up from current position (-> (zip/from-cursor '[1 2 [3 4 |]]) (move-up?)) => true
(next zip)
move cursor through the tree in depth first order
(->> (from-cursor '[| 1 [2 [6 7] 3] [4 5]]) (iterate next) (take-while identity) (map node)) => '(1 [2 [6 7] 3] 2 [6 7] 6 7 3 [4 5] 4 5)
move cursor through the tree in depth first order (->> (from-cursor '[| 1 [2 [6 7] 3] [4 5]]) (iterate next) (take-while identity) (map node)) => '(1 [2 [6 7] 3] 2 [6 7] 6 7 3 [4 5] 4 5)
(node zip)
accesses the node directly right of the cursor
(-> (from-cursor [1 '| 2 3]) (node)) => 2
accesses the node directly right of the cursor (-> (from-cursor [1 '| 2 3]) (node)) => 2
(postwalk zip f)
emulates clojure.walk/postwalk behavior with zipper
(-> (vector-zip [1 [2 [6 7] 3] [4 5]]) (find-next even?) (up) (postwalk (fn [v] (if (vector? v) (conj v 100) (+ v 100)))) (root-node)) => [1 [102 [106 107 200] 103 100] [4 5]]
emulates clojure.walk/postwalk behavior with zipper (-> (vector-zip [1 [2 [6 7] 3] [4 5]]) (find-next even?) (up) (postwalk (fn [v] (if (vector? v) (conj v 100) (+ v 100)))) (root-node)) => [1 [102 [106 107 200] 103 100] [4 5]]
(prev zip)
move cursor in reverse through the tree in depth first order
(->> (from-cursor '[1 [2 [6 7] 3] [4 | 5]]) (iterate prev) (take 10) (map node)) => '(5 4 [4 5] 3 7 6 [6 7] 2 [2 [6 7] 3] 1)
move cursor in reverse through the tree in depth first order (->> (from-cursor '[1 [2 [6 7] 3] [4 | 5]]) (iterate prev) (take 10) (map node)) => '(5 4 [4 5] 3 7 6 [6 7] 2 [2 [6 7] 3] 1)
(prewalk zip f)
emulates clojure.walk/prewalk behavior with zipper
(-> (vector-zip [1 [2 [6 7] 3] [4 5]]) (prewalk (fn [v] (if (vector? v) (conj v 100) (+ v 100)))) (root-node)) => [101 [102 [106 107 200] 103 200] [104 105 200] 200]
emulates clojure.walk/prewalk behavior with zipper (-> (vector-zip [1 [2 [6 7] 3] [4 5]]) (prewalk (fn [v] (if (vector? v) (conj v 100) (+ v 100)))) (root-node)) => [101 [102 [106 107 200] 103 200] [104 105 200] 200]
(replace-left {:keys [left] :as zip} element)
replace element left of the current position
(-> (zip/from-cursor '[1 2 | 3]) (replace-left "10") (zip/cursor)) => '([1 "10" | 3])
replace element left of the current position (-> (zip/from-cursor '[1 2 | 3]) (replace-left "10") (zip/cursor)) => '([1 "10" | 3])
(replace-right {:keys [right] :as zip} element)
replace element right of the current position
(-> (zip/from-cursor '[1 2 | 3]) (replace-right "10") (zip/cursor)) => '([1 2 | "10"])
replace element right of the current position (-> (zip/from-cursor '[1 2 | 3]) (replace-right "10") (zip/cursor)) => '([1 2 | "10"])
(right zip)
move cursor right (-> (from-cursor [1 '| 2 3]) (right) (cursor)) => '([1 2 | 3])
move cursor right (-> (from-cursor [1 '| 2 3]) (right) (cursor)) => '([1 2 | 3])
(right-most? zip)
check if at right-most point of a branch
(-> (zip/from-cursor '[1 2 [3 4 |]]) (right-most?)) => true
check if at right-most point of a branch (-> (zip/from-cursor '[1 2 [3 4 |]]) (right-most?)) => true
(right-node zip)
element directly right of current position
(-> (zip/from-cursor '[1 2 3 | 4]) (right-node)) => 4
element directly right of current position (-> (zip/from-cursor '[1 2 3 | 4]) (right-node)) => 4
(right-nodes zip)
all elements right of current position
(-> (zip/from-cursor '[1 2 | 3 4]) (right-nodes)) => '(3 4)
all elements right of current position (-> (zip/from-cursor '[1 2 | 3 4]) (right-nodes)) => '(3 4)
(root-node zip)
accesses the top level node
(-> (vector-zip [[[3] 2] 1]) (move-bottom-most) (root-node)) => [[[3] 2] 1]
accesses the top level node (-> (vector-zip [[[3] 2] 1]) (move-bottom-most) (root-node)) => [[[3] 2] 1]
(seq-zip root)
constructs a sequence zipper
(seq-zip '(1 2 3 4 5)) => (contains {:left (), :right '((1 2 3 4 5)), :parent :top})
constructs a sequence zipper (seq-zip '(1 2 3 4 5)) => (contains {:left (), :right '((1 2 3 4 5)), :parent :top})
(siblings {:keys [left right] :as zip})
all elements left and right of current position
(-> (zip/from-cursor '[1 2 | 3 4]) (siblings)) => '(1 2 3 4)
(-> (zip/from-cursor '[1 [2 | 3] 4]) (siblings)) => '(2 3)
all elements left and right of current position (-> (zip/from-cursor '[1 2 | 3 4]) (siblings)) => '(1 2 3 4) (-> (zip/from-cursor '[1 [2 | 3] 4]) (siblings)) => '(2 3)
(surround zip)
(surround zip num)
adds additional levels to the element
(-> (vector-zip 1) (surround 2) (root-node)) => [[1]]
adds additional levels to the element (-> (vector-zip 1) (surround 2) (root-node)) => [[1]]
(top-most? zip)
check if at top-most point of the tree
(-> (zip/from-cursor [1 2 [3 4 '|]]) (top-most?)) => false
(-> (zip/from-cursor '[1 2 [3 4 |]]) (move-up) (move-up) (top-most?)) => true
check if at top-most point of the tree (-> (zip/from-cursor [1 2 [3 4 '|]]) (top-most?)) => false (-> (zip/from-cursor '[1 2 [3 4 |]]) (move-up) (move-up) (top-most?)) => true
(traverse zip command)
(traverse zip command & more)
traverse through zipper with data
(-> (traverse (vector-zip [1 [[2] 3]]) :down :right [:down 2] [:right] [:insert-right 1 2 3 4]) (cursor)) => '([1 [[2 | 4 3 2 1] 3]])
traverse through zipper with data (-> (traverse (vector-zip [1 [[2] 3]]) :down :right [:down 2] [:right] [:insert-right 1 2 3 4]) (cursor)) => '([1 [[2 | 4 3 2 1] 3]])
(up zip)
move cursor up
(-> (from-cursor [1 '| 2 3]) (up) (cursor)) => '(| [1 2 3])
(-> (from-cursor [1 [['| 2] 3]]) (up) (cursor)) => '([1 [| [2] 3]])
move cursor up (-> (from-cursor [1 '| 2 3]) (up) (cursor)) => '(| [1 2 3]) (-> (from-cursor [1 [['| 2] 3]]) (up) (cursor)) => '([1 [| [2] 3]])
(vector-zip root)
constructs a vector based zipper
(vector-zip [1 2 3 4 5]) => (contains {:left (), :right '([1 2 3 4 5]) :parent :top})
constructs a vector based zipper (vector-zip [1 2 3 4 5]) => (contains {:left (), :right '([1 2 3 4 5]) :parent :top})
(zipper root {:keys [branch? children make-node] :as meta})
constructs a zipper
(zipper '(1 2 3) {:branch? seq? :children identity :make-node identity}) => zipper?
constructs a zipper (zipper '(1 2 3) {:branch? seq? :children identity :make-node identity}) => zipper?
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close