Skip to content

Instantly share code, notes, and snippets.

@aboekhoff
Created June 28, 2010 09:12
Show Gist options
  • Save aboekhoff/455612 to your computer and use it in GitHub Desktop.
Save aboekhoff/455612 to your computer and use it in GitHub Desktop.
(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