Skip to content

Instantly share code, notes, and snippets.

@thurt
Last active June 25, 2016 01:43
Show Gist options
  • Save thurt/2685c32774bc9f4c03ca35ed8928dee9 to your computer and use it in GitHub Desktop.
Save thurt/2685c32774bc9f4c03ca35ed8928dee9 to your computer and use it in GitHub Desktop.
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