Created
February 2, 2010 00:11
-
-
Save raek/292210 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 pred-get | |
"Steps through all the keys in pred-map, which are mutually exclusive | |
predicates, finds the first one that returns true when passed expr, and | |
returs the value associated with that predicate. | |
(map #(pred-get {neg? -1, zero? 0, pos? 1} %) [5 -2 0]) => (1 -1 0)" | |
[pred-map expr] | |
(loop [preds (keys pred-map)] | |
(when-first [pred preds] | |
(if (pred expr) | |
(get pred-map pred) | |
(recur (rest preds)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment