Skip to content

Instantly share code, notes, and snippets.

@scottcorgan
Created January 19, 2016 21:25
Show Gist options
  • Save scottcorgan/a108d6263df18322a5dc to your computer and use it in GitHub Desktop.
Save scottcorgan/a108d6263df18322a5dc to your computer and use it in GitHub Desktop.
node pipe vs rx.js
// Node streams
import through from 'through2'
function doSomethingToStream (config) {
return through((chunk, enc, next) {
next(/* do somethig here */)
})
}
// VS
// Rx.js
function doSomethingToObservable (input$) {
return input$.map(/* do somethign */)
}
@mattpodwysocki
Copy link

Maybe something such as this where you process each chunk and transform it? Chances are each source may be an Observable so it will just naturally work.

function processInput(data) {
  return Rx.Observable.create(observer => {
    // Do any data retrieval, etc
    const newData = process(data);
    observer.onNext(newData)
  });
}

var transformed = source.flatMap(data => {
  return processInput(data);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment