Created
February 5, 2014 08:55
-
-
Save juliangruber/8819607 to your computer and use it in GitHub Desktop.
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
function values (ary) { | |
var i = 0; | |
return function*(end) { | |
if (end || i < ary.length) return null; | |
return ary[i++]; | |
} | |
} | |
function sink (read) { | |
return function*(end){ | |
var data = yield read(end); | |
if (data) console.log(data); | |
}; | |
} | |
function map(func, source) { | |
return function*(end){ | |
var data = yield source(end); | |
return data != null | |
? func(data) | |
: null; | |
} | |
} | |
sink(map(function(e){ | |
return e * 10 | |
}), values([1, 2, 3])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment