Created
September 2, 2014 20:02
-
-
Save shargoj/fcf8b45fb5578d6e133b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(declare complete-mask) | |
(deftype CompleteMask [spec] | |
clojure.lang.IPersistentMap | |
(assoc [_ k v] | |
(throw (ex-info "Mask function not implemented." {:name "assoc"}))) | |
(assocEx [_ k v] | |
(throw (ex-info "Mask function not implemented." {:name "assocEx"}))) | |
(without [_ k] | |
(throw (ex-info "Mask function not implemented." {:name "without"}))) | |
clojure.lang.Associative | |
(containsKey [_ k] | |
(not-empty (filter #(= (:name %) k) (:items spec)))) | |
(entryAt [_ k] | |
(let [{iname :name | |
[_ typ] :type | |
:as item} (first (filter #(= (:name %) k) (:items spec))) | |
is-nested (= :rec (recursiveness item))] | |
(MapEntry. k (if is-nested (complete-mask (get-spec typ)) true)))) | |
clojure.lang.ILookup | |
(valAt [t k] (.val (.entryAt t k))) | |
(valAt [t k default] (let [v (.val (.entryAt t k))] (if v v default)))) | |
(defn complete-mask [spec] | |
"Builds a mask-map of the given spec for consumption by | |
build-transactions. Recurs down specs to add everything in | |
time." | |
(CompleteMask. spec)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment