Created
March 14, 2010 18:03
-
-
Save noidi/332107 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 fmap | |
"Filtering map. Like map, but removes nils from the result seq." | |
[& args] | |
(filter identity (apply map args))) | |
(defn update-matching | |
"Updates the given object(s) with fns selected by predicates. | |
(update-matching object(s) predicate-fn*) | |
predicate-fn => predicate update-fn | |
If the predicates of several update fns match, they are called in the | |
order in which they were given." | |
[object & predicate-fns] | |
(let [update-fns (fmap (fn [[predicate update-fn]] | |
(when (predicate object) | |
update-fn)) | |
(partition 2 predicate-fns))] | |
((apply comp (reverse update-fns)) object))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment