-
-
Save phpsmarter/ddaf9e14c7de0b8d83b3d839dfe4df6c 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