I'm using RxJS 5.0.0-alpha.12 to perform some data transformations, and some of those transformations use Promises.return observable.flatMap(item => {  return Observable.zip(    Observable.fromPromise(fs.readFile('./config.json')),    Observable.of(item),    (s1, s2) => {      return {        config: JSON.parse(s1.toString()),        testResult: s2      };    }  );}).flatMap(item => {  return Observable.zip(    Observable.fromPromise(      getStudentIdFromStudentNumber(item.testResult['Student Primary ID'])    ),    Observable.of(item),    (s1, s2) => {      return {        'Test Date': s2.config.testConstants.ROGL_Begin_Year.testDate,        'Student Id': s1,        'Student Number': s2.testResult['Student Primary ID'],        'Grade Level': s2.testResult.Grade,        'Composite Score Alpha': s2.testResult['Composite Score']      };    }  );});Note that both fs.readFile (fs here being the name given to fs-promise) and getStudentIdFromStudentNumber return a Promise.It seems like having to zip the original item that is getting emitted from observable with the results of each Promise is cumbersome. Is there a cleaner way to use the results of these two Promises with this Observable?What makes this tricky (to me) is sometimes the Promise relies on a field within the item object emitted by observable (eg., getStudentIdFromStudentNumber), and other Promises may not rely on item (eg., fs.readFile).
Performing data transportations in RxJS with Promises
javascript;promise;reactive programming
You are (twice) using Observable.of(item), this is redundant as item is already in scope.Also, you can call both promises in parallel. zip is perfect for exactly that.If you want to make transformations to an item before you use it, put a map inside the zip. For example, we can extract the testDate early.While we're on it, we can use meaningfull variable names.If you have more than 2 promises, zip will happily accept 3, 4 or more arguments.Lastly we use flatMap around the zip to flatten the stream of zip observables back to items.return observable  .flatMap(item => {    return Observable.zip(      Observable.fromPromise(fs.readFile('./config.json'))      .map(config => JSON.parse(config.toString().testConstants.ROGL_Begin_Year.testDate))      , Observable.fromPromise(        getStudentIdFromStudentNumber(item.testResult['Student Primary ID'])      ), (testDate, id) => {        return {          'Test Date': testDate,          'Student Id': id,          'Student Number': item['Student Primary ID'],          'Grade Level': item.Grade,          'Composite Score Alpha': item['Composite Score']        };      }    )  });