                                expr)
                              ([expr idx]
                                (let [matcher-sym (get matcher-syms idx)
+                                     matcher-exp (if-let [matchex (:matchex (get routes idx))]
+                                                   (matchex request-sym)
+                                                   `(~matcher-sym ~request-sym))
                                      handler-sym (get handler-syms idx)]
-                                 `(if-let [match# (~matcher-sym ~request-sym)]
+                                 `(if-let [match# ~matcher-exp]
                                     (let [request# (get match# :request ~request-sym)
                                           ^Map params#  (get match# :params)]
                                       (~handler-sym request#

  corresponding route handler on successful match, returns nil otherwise.
  Synopsis:
  0. A route is a map {:matcher arity-1 fn  ; :matcher is a required key
                       :nested  route-map   ; either of :nested and :handler keys must be present
                       :handler arity-3 fn}
  1. A matcher is arity-1 fn (accepts request as argument) that returns {:request request :params route-param-map}
     on successful match, nil otherwise. A matcher may update the request (on successful match) before passing it on.
  2. Handler is arity-2 function (accepts request and match-param-map as arguments)."
  [routes]
  (let [routes (->> routes
                 (map (fn [spec]

        (do
          (when-not (string? uri-pattern)
            (i/expected "URI pattern to be retrievable as a string value" spec))
          (let [uri-template (i/parse-uri-template i/default-separator uri-pattern)
                ensure-matchex (make-ensurer :matchex
                                 (fn [spec x]
                                   (assoc spec :matchex x)))]
            (-> spec
              (assoc :matcher (fn [request]
                                (when-let [params (Util/matchURI ^String (:uri request) uri-template)]
                                  {:params params})))
              (ensure-matchex (fn [request]
                                `(when-let [params# (Util/matchURI ^String (:uri ~request) ~uri-template)]
                                   {:params params#}))))))
        spec))))


