Created
March 24, 2012 09:03
-
-
Save be5invis/2180426 to your computer and use it in GitHub Desktop.
Enumerator comprehension 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
-- Enumerator comprehension monad | |
var ecSchemata = [yield: fYield, return: fReturn, bind: fBind] | |
where | |
fReturn = Enumerable function(x): | |
if(x != undefined) | |
enumeration.yield! x | |
fYield(x) = x | |
fBind = Enumerable function(list, callback): | |
for(var x in list) | |
for(var y in callback x) | |
enumeration.yield! y | |
var table(G) = | |
var f = G.build ecSchemata | |
f.apply(this, arguments)() | |
var t = table => | |
var x <- (1...9) | |
var y <- (1...9) | |
if(x <= y) | |
x + ' * ' + y + ' = ' + x * y | |
for(var item in t) trace item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment