I'm playing around with two excellent libraries: js-csp and transducers.js trying to wrap my head around them (and generators).
I think I got a decent understanding of using channels, but when I decided to apply transducers (which I don't quite understand that well yet) to them I can't seem to make it work. Not even the examples are working for me.
The specific transducers.js file I use, is this one, and for js-csp, I compiled my own (which has been working fine for many other experiments). Basically I compiled a file with this:
import csp from 'js-csp';
window.csp = csp;
with browserify v.9.0.3 and babel v.5.0.8.
Here's some sample code that I'd expect to work:
// 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); // This throws an error
What am I missing? To me this is essentially the same as what can be found in the documentation for js-csp here, and for transducers here (2nd to last bullet point).
The csp library is helpful enough to throw an error with a stack trace. Looks like this:
error in channel transformer TypeError: xform.@@transducer/step is not a function
at Object.@@transducer/step (file:///Users/g/code/learning/generators-csp/js/lib/csp.js:1511:44)
at Channel._put (file:///Users/g/code/learning/generators-csp/js/lib/csp.js:1288:57)
at put_then_callback (file:///Users/g/code/learning/generators-csp/js/lib/csp.js:1652:24)
at file:///Users/g/code/learning/generators-csp/js/12-transducers-1.js:21:10
What am I doing wrong? A working example (as simple as possible) would be very helpful too.
Everything can be found on my github, here. With the specific, identical to the code above, here, the csp and transducers can be found in the js/lib folder.