haskell: Phase 11 — Data.Map combining (unionWith/intersectionWith/difference)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m56s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 10:00:45 +00:00
parent 12de24e3a0
commit 95cf653ba9
2 changed files with 57 additions and 1 deletions

View File

@@ -320,3 +320,52 @@
(append
(hk-map-elems (hk-map-left m))
(cons (hk-map-val m) (hk-map-elems (hk-map-right m))))))))
(define
hk-map-union-with
(fn
(f m1 m2)
(reduce
(fn
(acc p)
(let
((k (first p)) (v (nth p 1)))
(let
((look (hk-map-lookup k acc)))
(cond
((= (first look) "Just")
(hk-map-insert k (f (nth look 1) v) acc))
(:else (hk-map-insert k v acc))))))
m1
(hk-map-to-asc-list m2))))
(define
hk-map-intersection-with
(fn
(f m1 m2)
(reduce
(fn
(acc p)
(let
((k (first p)) (v1 (nth p 1)))
(let
((look (hk-map-lookup k m2)))
(cond
((= (first look) "Just")
(hk-map-insert k (f v1 (nth look 1)) acc))
(:else acc)))))
hk-map-empty
(hk-map-to-asc-list m1))))
(define
hk-map-difference
(fn
(m1 m2)
(reduce
(fn
(acc p)
(let
((k (first p)) (v (nth p 1)))
(cond ((hk-map-member k m2) acc) (:else (hk-map-insert k v acc)))))
hk-map-empty
(hk-map-to-asc-list m1))))