Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.