Skip to content

Instantly share code, notes, and snippets.

@agrison
Created October 21, 2019 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrison/85fbffdb29a5bf68cd6dca166af3f23d to your computer and use it in GitHub Desktop.
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
(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