Skip to content

Instantly share code, notes, and snippets.

@dominem
Created March 22, 2020 15:26
Show Gist options
  • Save dominem/052ad9f9764a0cf8bd3904a4efa39ffa to your computer and use it in GitHub Desktop.
Save dominem/052ad9f9764a0cf8bd3904a4efa39ffa to your computer and use it in GitHub Desktop.
(defn my-comp
([f g]
(fn [& args]
(f (apply g args))))
([f g & fns]
(fn [& args]
(f (g (reduce (fn [result next-f] (next-f result))
(apply (last fns) args)
(reverse (butlast fns))))))))
(comment
((my-comp inc *) 2 3)
;; => 7
((my-comp inc inc *) 2 3)
;; => 8
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment