Skip to content

Instantly share code, notes, and snippets.

@nooga
Last active March 1, 2016 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nooga/1cf8934e12d19299e742 to your computer and use it in GitHub Desktop.
Save nooga/1cf8934e12d19299e742 to your computer and use it in GitHub Desktop.
fun fun fun
(defprotocol IJournalMap
(journal [_]))
(deftype JournalMap [journal data]
IJournalMap
(journal [_] journal)
clojure.lang.ILookup
(valAt [this key] (get data key))
(valAt [this key nf] (get data key nf))
clojure.lang.IPersistentMap
(assoc [this k v]
(JournalMap. (conj journal k) (assoc data k v)))
(without [this k]
(JournalMap. journal (dissoc data k)))
clojure.lang.Associative
(containsKey [this k]
(some? (get data k)))
(entryAt [this k]
(get data k))
clojure.lang.Counted
(count [this]
(count data))
clojure.lang.Seqable
(seq [_]
(seq data))
Object
(toString [this] (str "JournalMap" this)))
;;user> ((juxt class identity journal) (-> (->JournalMap [] {})
;; (assoc :x 6 :y 5)
;; (dissoc :y)
;; (update :x inc)))
;;[JournalMap {:x 7} [:x :y :x]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment