Created
October 21, 2019 14:55
-
-
Save agrison/85fbffdb29a5bf68cd6dca166af3f23d to your computer and use it in GitHub Desktop.
Write a function that takes the identity and the 2-arg case and returns a new function that implements the monoid pattern
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 monoid [id f] | |
(fn | |
([] id) | |
([a] (f id a)) | |
([a b] (f a b)) | |
([a b & more] (reduce f (f a b) more)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment