Last active
September 6, 2023 17:04
-
-
Save kidd/a771ee9488fac8cd4ffb0d87dfbc0097 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 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