Last active
January 21, 2016 06:05
-
-
Save baritonehands/b75dc69242948308ff3d 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
(defprotocol CRUD | |
(create [this entity]) | |
(get [this id]) | |
(save [this id updates]) | |
(delete [this id])) | |
(defn create-db [] | |
(let [db (ref {})] | |
(reify CRUD | |
(create [_ entity] | |
(let [id (str (java.util.UUID/randomUUID))] | |
(dosync (alter db assoc id (assoc entity :id id))) | |
entity)) | |
(get [_ id] | |
(@db id)) | |
(save [_ id updates] | |
(dosync (alter db update-in [id] merge updates))) | |
(delete [_ id] | |
(dosync (dissoc db id)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment