Skip to content

Instantly share code, notes, and snippets.

@kidd
Last active September 6, 2023 17:04
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 kidd/a771ee9488fac8cd4ffb0d87dfbc0097 to your computer and use it in GitHub Desktop.
Save kidd/a771ee9488fac8cd4ffb0d87dfbc0097 to your computer and use it in GitHub Desktop.
(defn apply-if
"if(p(m)) then f(m, ...args) else m
Useful for `maybe-*` like updates."
[m p f & args]
(if (p m)
(apply f m args)
m))
(defn fork [l c r]
#(->> % ((juxt l r)) (apply c)))
(defn avg [a]
((fork (partial apply +) / count) a))
(defn unique? [a]
((fork count = (comp count set)) a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment