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