Skip to content

Instantly share code, notes, and snippets.

@domkm
Last active August 29, 2015 14:05
Show Gist options
  • Save domkm/26658b53a50e48f0be70 to your computer and use it in GitHub Desktop.
Save domkm/26658b53a50e48f0be70 to your computer and use it in GitHub Desktop.
(defrecord User [id])
; --------------------
; unmatch on Routes
(def routes
(silk/routes [[User ["users" (silk/integer :id)]]]))
(silk/unmatch routes User (User. 42)) ; you can use a record as a params map
; or use a helper function to generate a URL
(defn unmatch-type [rtes obj]
(silk/unmatch rtes (type obj) obj))
; --------------------
; unmatch on Route
(def user-route
(silk/route [User ["users" (silk/integer :id)]]))
(silk/unmatch user-route (User. 42))
; --------------------
; implement `Pattern` and unmatch on type directly
(extend-protocol silk/Pattern
User
(-unmatch [this _]
(silk/url {:path ["users" (-> this :id str)]})))
(silk/unmatch (User. 42) {})
; I would consider adding a unary version of `unmatch` if this last one is a common request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment