Last active
March 1, 2016 21:21
-
-
Save nooga/1cf8934e12d19299e742 to your computer and use it in GitHub Desktop.
fun fun fun
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
(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