Last active
December 2, 2020 09:27
-
-
Save conf8o/16ce6a4f9edbaae02074390e2e2a5109 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 maybe-comp | |
"Composes functions, maybe :). The returned fn returns nil if anyone does so." | |
([f] f) | |
([f g] | |
(fn | |
([] (when-let [a (g)] | |
(f a))) | |
([x & args] (when-let [a (apply g x args)] | |
(f a))))) | |
([f g & fs] | |
(reduce maybe-comp (list* f g fs)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment