Skip to content

Instantly share code, notes, and snippets.

@phpsmarter
Forked from michiel/transducer-rxjs-ramda.js
Created January 25, 2018 03:28
Show Gist options
  • Save phpsmarter/ddaf9e14c7de0b8d83b3d839dfe4df6c to your computer and use it in GitHub Desktop.
Save phpsmarter/ddaf9e14c7de0b8d83b3d839dfe4df6c to your computer and use it in GitHub Desktop.
transducer in es6 with ramda and rxjs
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