Last active
June 25, 2016 01:43
-
-
Save thurt/2685c32774bc9f4c03ca35ed8928dee9 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
const R = require('ramda') | |
// changes input into an iterable and returns it | |
function producer() { | |
return Array.from(arguments) | |
} | |
function map(fn) { | |
return function* (iterable) { | |
for (let i of iterable) { | |
yield fn(i) | |
} | |
} | |
} | |
// pulls iterable values through the composed transforms in order to produce output | |
function consumer(transforms) { | |
const list = [] | |
for (let i of transforms) { | |
list.push(i) | |
console.log(list) // side-effect | |
} | |
} | |
function main() { | |
const pipeline = R.pipe( | |
producer, | |
map(R.compose(R.inc, R.inc)), | |
consumer) | |
pipeline(1,1,1) | |
/* Logs | |
[ 3 ] | |
[ 3, 3 ] | |
[ 3, 3, 3 ] | |
*/ | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment