Skip to content

Instantly share code, notes, and snippets.

@michaelsbradleyjr
Created November 10, 2012 05:44
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 michaelsbradleyjr/4050049 to your computer and use it in GitHub Desktop.
Save michaelsbradleyjr/4050049 to your computer and use it in GitHub Desktop.
Monadic plus for list transformer with set monad
(require '[clojure.algo.monads :as am])
(require '[monads.core :as m])
;-------------- algo.monads version #1 ---------------;
(def set-sequence-m (am/sequence-t am/set-m))
(am/with-monad set-sequence-m
(am/m-plus #{(list 1 2)} #{(list)} #{(list 3 4)}))
;; => #{() (3 4) (1 2)}
;-------------- algo.monads version #2 ---------------;
(def set-sequence-m (am/sequence-t am/set-m :m-plus-from-transformer))
(am/with-monad set-sequence-m
(am/m-plus #{(list 1 2)} #{(list)} #{(list 3 4)}))
;; => #{(1 2 3 4)}
;-------------- protocol-monads version --------------;
(def set-list (m/list-t hash-set))
@(m/plus [(set-list 1 2) (set-list) (set-list 3 4)])
;; => #{(1 2 3 4)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment