haskell: Phase 11 — Data.Map bulk ops (fromList/toList/toAscList/keys/elems)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m58s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 09:32:30 +00:00
parent 180b9009bf
commit 12de24e3a0
2 changed files with 55 additions and 1 deletions

View File

@@ -274,3 +274,49 @@
(hk-map-left m)
(hk-map-delete k (hk-map-right m))))
(:else (hk-map-glue (hk-map-left m) (hk-map-right m)))))))))
(define
hk-map-from-list
(fn
(pairs)
(reduce
(fn (acc p) (hk-map-insert (first p) (nth p 1) acc))
hk-map-empty
pairs)))
(define
hk-map-to-asc-list
(fn
(m)
(cond
((hk-map-empty? m) (list))
(:else
(append
(hk-map-to-asc-list (hk-map-left m))
(cons
(list (hk-map-key m) (hk-map-val m))
(hk-map-to-asc-list (hk-map-right m))))))))
(define hk-map-to-list hk-map-to-asc-list)
(define
hk-map-keys
(fn
(m)
(cond
((hk-map-empty? m) (list))
(:else
(append
(hk-map-keys (hk-map-left m))
(cons (hk-map-key m) (hk-map-keys (hk-map-right m))))))))
(define
hk-map-elems
(fn
(m)
(cond
((hk-map-empty? m) (list))
(:else
(append
(hk-map-elems (hk-map-left m))
(cons (hk-map-val m) (hk-map-elems (hk-map-right m))))))))