Skip to content

Instantly share code, notes, and snippets.

@michaelsbradleyjr
Created November 10, 2012 05:59
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/4050099 to your computer and use it in GitHub Desktop.
Save michaelsbradleyjr/4050099 to your computer and use it in GitHub Desktop.
Monadic plus for list transformer with list monad
(require '[clojure.algo.monads :as am])
(require '[monads.core :as m])
;-------------- algo.monads version #1 ---------------;
(def sequence-sequence-m (am/sequence-t am/sequence-m))
(am/with-monad sequence-sequence-m
(am/m-plus (list (list 1 2 )) (list (list)) (list (list 3 4))))
;; => ((1 2) () (3 4))
;-------------- algo.monads version #2 ---------------;
(def sequence-sequence-m (am/sequence-t am/sequence-m :m-plus-from-transformer))
(am/with-monad sequence-sequence-m
(am/m-plus (list (list 1 2 )) (list (list)) (list (list 3 4))))
;; => ((1 2 3 4))
;-------------- protocol-monads version --------------;
(def list-list (m/list-t list))
@(m/plus [(list-list 1 2) (list-list) (list-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