Created
February 22, 2016 15:52
-
-
Save michiel/87a30247fbddefdef961 to your computer and use it in GitHub Desktop.
transducer in es6 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
const Rx = require('rx'); | |
const R = require('ramda'); | |
const seq = Rx.Observable.range(1, 10); | |
const isEven = (x) => x % 2 === 0; | |
const add1 = (x) => x + 1; | |
const transducer = R.compose( | |
R.map(add1), | |
R.filter(isEven) | |
); | |
const source = seq.transduce(transducer); | |
source.subscribe( | |
/* onNext */ (i) => { | |
console.log(i); | |
}, | |
/* onError */ (err) => { | |
console.error(err); | |
}, | |
/* onComplete */ () => { | |
console.log('All done'); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Was just playing with this and looking at RxJS v5…does this seem like a sensible translation (given there is no
transduce
operator):