insert-child

clojure.zip

  • (insert-child loc item)
Inserts the item as the leftmost child of the node at this loc,
without moving

1 Example top

  • (use 'clojure.zip) ;;warnings OK
    
    (def zp (zipper vector? seq (fn [_ c] c) [[1 2 3] [4 [5 6] 7] [8 9]]) )
    
    (root (insert-child (-> zp down right) 42))
    =>([1 2 3] (42 4 [5 6] 7) [8 9])
    
    
    (def zp2 (zipper vector? seq (fn [_ c] c) [74 75])
    
    (root (insert-right (-> zp down right) zp2))
    =>([1 2 3] [4 [5 6] 7] [[74 75] nil] [8 9])
    
    (root (insert-left (-> zp down right) zp2))
    =>([1 2 3] [[74 75] nil] [4 [5 6] 7] [8 9])
    
    
    
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/zip.clj:216 top

(defn insert-child
  "Inserts the item as the leftmost child of the node at this loc,
  without moving"
  {:added "1.0"}
  [loc item]
    (replace loc (make-node loc (node loc) (cons item (children loc)))))
Vars in clojure.zip/insert-child:
Used in 0 other vars

Comments top

No comments for insert-child. Log in to add a comment.