application/octet-stream
•
1.03 KB
•
31 lines
;;; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
;;; This project uses the MIT license, a copy should be included under /LICENSE
;;;
;;; Some functions using maps
(defn map/zip (keys values)
"Return a Map where KEYS point to VALUES"
(def ret (map/new))
(doseq (key keys ret)
(set! ret key (car values))
(cdr! values)))
(defn map/reduce (l o s)
"Combine all elements in l using operation o and starting value s"
(list/reduce (:values l) o s))
(defn map/filter (l f)
"Return a new Map with all elements from L where F returns true"
(def ret (map/new))
(doseq (e (:keys l) ret)
(def t (ref l e))
(when (f t)
(set! ret e t))))
(defn map/merge (a b)
"Merge two Maps together, if a key is contained in both trees the on in B gets priority"
(when-not b (return (if a (:clone a) {})))
(when-not a (return (:clone b)))
(def ret (:clone a))
(doseq (k (:keys b) ret)
(set! ret k (ref b k))))