Skip to content

Instantly share code, notes, and snippets.

@luxbock
Last active June 18, 2016 14:47
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 luxbock/fda8f2ee4e642903d532d1b34db902e5 to your computer and use it in GitHub Desktop.
Save luxbock/fda8f2ee4e642903d532d1b34db902e5 to your computer and use it in GitHub Desktop.
(defn get-apply
[m & fields]
(loop [this-m m
[f & fs] fields]
(when-let [v (get this-m f)]
(cond
(map? v) (recur v fs)
(ifn? v) (apply v fs)
:else v))))
(defn get-rule
[rules & fields]
(or
(apply get-apply rules fields)
(apply get-apply rules :default (drop 2 fields))
(throw (ex-info "Lookup failure!" {:fields fields}))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment