Commits

Moritz Heidkamp committed 8fa44d4

Add map-merge

Comments (0)

Files changed (2)

persistent-hash-map.scm

  map-each
  map-collect
  map-keys
- map-values)
+ map-values
+ map-merge)
 
 (import (except chicken define-record-type)
         foreign
 (define (map-values map)
   (map-collect (lambda (k v) v) map))
 
+(define (map-merge m1 m2)
+  (persist-map!
+   (map-reduce (lambda (k v m)
+                 (map-assoc! m k v))
+               (map->transient-map m1)
+               m2)))
+
 (define (print-map type map out)
   (display "#<" out)
   (display type out)
           (test 51 (map-size tm))
           (test 2 (map-ref tm key-b))))))
 
+(test-group "map-merge"
+  (let ((m (map-merge (persistent-map 1 2 3 4)
+                      (persistent-map 1 3 5 6))))
+    (test 3 (map-ref m 1))
+    (test 4 (map-ref m 3))
+    (test 6 (map-ref m 5))))
+
 (test-end)
 
 (test-exit)