Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns combinatrix.sequence
(:use combinatrix.core))
(defmonad
:name :sequence
:do in-sequence
:bind (fn [mv f] (mapcat (fn [x] (f x)) mv))
:return list
:zero ()
:plus concat
:modules [base maybe])
(defn simple-sequence []
(in-sequence
x <- (range 3)
y <- (range 7 11)
:when (even? y)
(return [x y])))
(comment
(simple-sequence)
=> ([0 8] [0 10] [1 8] [1 10] [2 8] [2 10])
(sum (simple-sequence))
=> (0 8 0 10 1 8 1 10 2 8 2 10))
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.