Skip to content

Instantly share code, notes, and snippets.

@noidi
Created March 14, 2010 18:03
Show Gist options
  • Save noidi/332107 to your computer and use it in GitHub Desktop.
Save noidi/332107 to your computer and use it in GitHub Desktop.
(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