Skip to content

Instantly share code, notes, and snippets.

@clohr
Last active April 4, 2016 05:22
Show Gist options
  • Save clohr/9b24b640c30c86885def to your computer and use it in GitHub Desktop.
Save clohr/9b24b640c30c86885def to your computer and use it in GitHub Desktop.
Transducers with Ramda and RxJS
var Rx = require('rx');
var R = require('ramda');
var seq = Rx.Observable.range(1, 10);
var isEven = function isEven(x) { return x % 2 === 0; };
var add1 = function add1(x) { return x + 1; };
var transducer = R.compose(R.map(add1), R.filter(isEven));
var source = seq.transduce(transducer);
source.subscribe(
function onNext(i) {
document.body.textContent += ' ' + i;
},
function onErr(err) {
document.body.textContent += ' ' + err;
},
function onComplete() {
document.body.textContent += ' Done';
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment