Moritz Heidkamp  committed d49c035

Make update-in use #f as the default value for the innermost key

  • Participants
  • Parent commits 86705c5
  • Branches master

Comments (0)

Files changed (2)

File persistent-hash-map.scm

 (define (map-update-in map keys proc . args)
   (when (null? keys)
     (error 'map-update-in "Need at least one key"))
-  (let* ((key  (car keys))
-         (smap (map-ref map key +empty-persistent-hash-map+)))
+  (let ((key  (car keys)))
     (if (null? (cdr keys))
-        (map-add map key (apply proc smap args))
-        (map-add map key (apply map-update-in smap (cdr keys) proc args)))))
+        (map-add map key (apply proc (map-ref map key) args))
+        (map-add map key (apply map-update-in
+                                (map-ref map key +empty-persistent-hash-map+)
+                                (cdr keys)
+                                proc
+                                args)))))
 (define-record-printer (persistent-hash-map m out)
   (display "#<persistent-hash-map" out)

File tests/run.scm

 (test-group "map-ref-in, map-update-in"
   (let ((m (-> (persistent-map 'foo (persistent-map 'bar 1))
                (map-update-in '(foo bar) + 1)
-               (map-update-in '(foo baz) map-add 'qux 9))))
+               (map-update-in '(foo baz qux) (lambda (x) (or x 9))))))
     (test 2 (map-ref-in m '(foo bar)))
     (test 9 (map-ref-in m '(foo baz qux)))))