Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created October 11, 2010 21:06
Show Gist options
  • Save KirinDave/621229 to your computer and use it in GitHub Desktop.
Save KirinDave/621229 to your computer and use it in GitHub Desktop.
(defn get-route [route-map req]
(loop [routes (keys route-map)]
(let [route (first routes)]
(if (route-matches route req)
(get route-map route)
(recur (rest routes))))))
; This is one way
(defn get-route [route-map req]
(when-let [[route fun] (first (filter #(route-matches (first %) req) route-map))]
fun))
; With a default:
; This is one way to provide defaults
(defn get-route
([route-map req default]
(let [[route fun] (first (filter #(route-matches (first %) req) route-map))]
(or fun default)))
([route-map req] (get-route route-map reg nil)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment