Created
November 10, 2012 05:59
-
-
Save michaelsbradleyjr/4050099 to your computer and use it in GitHub Desktop.
Monadic plus for list transformer with list monad
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
(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