Skip to content

Instantly share code, notes, and snippets.

@joews
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joews/4d4b5510720427f75d00 to your computer and use it in GitHub Desktop.
Save joews/4d4b5510720427f75d00 to your computer and use it in GitHub Desktop.
// http://stackoverflow.com/q/29747951/2806996
var transducers = require('transducers.js');
var csp = require('js-csp')
// Make transducer
var xAdd10 = transducers.map(function (x) {
return x + 10;
});
// Make a channel, using the transducer
var ch = csp.chan(2, xAdd10);
// Put a number in the channel
csp.putAsync(ch, 1);
csp.takeAsync(ch, function(value) { console.log("Got ", value)});
// Output:
// ❯ node --harmony test.js
// Got 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment