Skip to content

Instantly share code, notes, and snippets.

@shargoj
Created September 2, 2014 20:02
Show Gist options
  • Save shargoj/fcf8b45fb5578d6e133b to your computer and use it in GitHub Desktop.
Save shargoj/fcf8b45fb5578d6e133b to your computer and use it in GitHub Desktop.
(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