Skip to content

Instantly share code, notes, and snippets.

@dball
Last active June 4, 2016 21:14
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 dball/e56f4a9c374d2d46073403f30c07d055 to your computer and use it in GitHub Desktop.
Save dball/e56f4a9c374d2d46073403f30c07d055 to your computer and use it in GitHub Desktop.
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