Performing data transportations in RxJS with Promises 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 =&gt; {
  return Observable.zip(

    Observable.fromPromise(fs.readFile('./config.json')),

    Observable.of(item),

    (s1, s2) =&gt; {
      return {
        config: JSON.parse(s1.toString()),
        testResult: s2
      };
    }
  );
})
.flatMap(item =&gt; {
  return Observable.zip(

    Observable.fromPromise(
      getStudentIdFromStudentNumber(item.testResult['Student Primary ID'])
    ),

    Observable.of(item),

    (s1, s2) =&gt; {
      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).
I would be more inclined to map with the flatMap to have my results flow through.

Something like the following, might do what you're looking for.

return observable
  .flatMap(item =&gt; Observable.fromPromise(fs.readFile('./config.json'))
    .map(file =&gt; ({ config: JSON.parse(file.toString()), testResult: item })))
  .flatMap(({ config, testResult }) =&gt; Observable.fromPromise(getStudentIdFromStudentNumber(item.testResult['Student Primary ID']))
    .map(id =&gt; ({
      'Test Date': config.testConstants.ROGL_Begin_Year.testDate,
      'Student Id': id,
      'Student Number': testResult['Student Primary ID'],
      'Grade Level': testResult.Grade,
      'Composite Score Alpha': testResult['Composite Score']
    })));