Skip to content

Instantly share code, notes, and snippets.

@conf8o
Last active December 2, 2020 09:27
Show Gist options
  • Save conf8o/16ce6a4f9edbaae02074390e2e2a5109 to your computer and use it in GitHub Desktop.
Save conf8o/16ce6a4f9edbaae02074390e2e2a5109 to your computer and use it in GitHub Desktop.
(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