Last active
April 4, 2016 05:22
-
-
Save clohr/9b24b640c30c86885def to your computer and use it in GitHub Desktop.
Transducers with Ramda and RxJS
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
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