Created
October 11, 2010 21:06
-
-
Save KirinDave/621229 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
(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