Skip to content

Instantly share code, notes, and snippets.

@dball
Last active June 4, 2016 21:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Protocol Example
(defprotocol UserStore
(load [_ id])
(save! [_ id user])
(delete! [_ id]))
(defrecord Database [db]
UserStore
(load [_ id]
(first (jdbc/query db ["select * from users where id = ?" id])))
...)
(defn build-memory-user-store
[]
(let [state (atom {})]
(reify UserStore
(load [_ id] (get @state id))
...)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment